Skip to content

Commit 2fd101b

Browse files
authored
Merge pull request #1511 from dpalou/MDL-72048
[docs] Document file locations for Moodle app code in plugins
2 parents bcccccb + 49975d0 commit 2fd101b

6 files changed

Lines changed: 30 additions & 15 deletions

File tree

general/app/development/plugins-development-guide/examples/course-formats.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class mobile {
3232

3333
$course = get_course($args['courseid']);
3434
require_login($course);
35-
$html = $OUTPUT->render_from_template('format_myformat/mobile_course', []);
35+
$html = $OUTPUT->render_from_template('format_myformat/mobileapp/mobile_course', []);
3636

3737
return [
3838
'templates' => [
@@ -50,7 +50,7 @@ class mobile {
5050
}
5151
```
5252

53-
```html handlebars title="templates/mobile_course.mustache"
53+
```html handlebars title="templates/mobileapp/mobile_course.mustache"
5454
{{=<% %>=}}
5555
<core-dynamic-component [component]="coreCourseFormatComponent.allSectionsComponent" [data]="data" class="format-myformat">
5656
@for (section of sections; track section.id) {

general/app/development/plugins-development-guide/examples/course-modules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class mobile {
111111
'templates' => [
112112
[
113113
'id' => 'main',
114-
'html' => $OUTPUT->render_from_template('mod_certificate/mobile_view_page', $data),
114+
'html' => $OUTPUT->render_from_template('mod_certificate/mobileapp/mobile_view_page', $data),
115115
],
116116
],
117117
'files' => $issues,
@@ -125,7 +125,7 @@ In the first part of the function, we check permissions and capabilities (like a
125125

126126
We also return a list of files to prefetch for offline use.
127127

128-
Finally, let's implement the mustache template in `templates/mobile_view_page.mustache`:
128+
Finally, let's implement the mustache template in `templates/mobileapp/mobile_view_page.mustache`:
129129

130130
```html handlebars
131131
{{=<% %>=}}
@@ -228,14 +228,14 @@ public static function mobile_issues_view($args) {
228228
'templates' => [
229229
[
230230
'id' => 'main',
231-
'html' => $OUTPUT->render_from_template('mod_certificate/mobile_view_issues', $data),
231+
'html' => $OUTPUT->render_from_template('mod_certificate/mobileapp/mobile_view_issues', $data),
232232
],
233233
],
234234
];
235235
}
236236
```
237237

238-
```html handlebars title="templates/mobile_view_issues.mustache"
238+
```html handlebars title="templates/mobileapp/mobile_view_issues.mustache"
239239
{{=<% %>=}}
240240
<div>
241241
<ion-list>

general/app/development/plugins-development-guide/examples/forms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class mobile {
1818
'templates' => [
1919
[
2020
'id' => 'main',
21-
'html' => $OUTPUT->render_from_template('local_hello/form', []),
21+
'html' => $OUTPUT->render_from_template('local_hello/mobileapp/form', []),
2222
],
2323
],
2424
'otherdata' => [

general/app/development/plugins-development-guide/examples/groups-selector.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ return [
3939
'templates' => [
4040
[
4141
'id' => 'main',
42-
'html' => $OUTPUT->render_from_template('local_sample/groups', []),
42+
'html' => $OUTPUT->render_from_template('local_sample/mobileapp/groups', []),
4343
],
4444
],
4545
'otherdata' => [
@@ -83,7 +83,7 @@ return [
8383
'templates' => [
8484
[
8585
'id' => 'main',
86-
'html' => $OUTPUT->render_from_template('local_sample/groups', [
86+
'html' => $OUTPUT->render_from_template('local_sample/mobileapp/groups', [
8787
'groups' => $groups,
8888
'selectedgroup' => $groups[$selectedgroup],
8989
]),

general/app/development/plugins-development-guide/examples/question-types.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class mobile {
4040
public static function mobile_get_YOURQTYPENAME() {
4141
global $OUTPUT, $CFG;
4242

43-
$html = $OUTPUT->render_from_template('qtype_YOURQTYPENAME/mobile', []);
43+
$html = $OUTPUT->render_from_template('qtype_YOURQTYPENAME/mobileapp/mobile', []);
4444

4545
return [
4646
'templates' => [
@@ -49,14 +49,14 @@ class mobile {
4949
'html' => $html,
5050
],
5151
],
52-
'javascript' => file_get_contents($CFG->dirroot . '/question/type/YOURQTYPENAME/mobile/mobile.js'),
52+
'javascript' => file_get_contents($CFG->dirroot . '/question/type/YOURQTYPENAME/js/mobileapp/mobile.js'),
5353
];
5454
}
5555

5656
}
5757
```
5858

59-
```html handlebars title="templates/mobile.mustache"
59+
```html handlebars title="templates/mobileapp/mobile.mustache"
6060
<section class="list qtype-YOURQTYPENAME-container qtype-YOURQTYPENAME" ion-list *ngIf="question.text || question.text === ''">
6161
<ion-item class="addon-qtype-YOURQTYPENAME-container qtext">
6262
<ion-label>
@@ -71,7 +71,7 @@ class mobile {
7171
</section>
7272
```
7373

74-
```js title="mobile/mobile.js"
74+
```js title="js/mobileapp/mobile.js"
7575
const that = this;
7676
const result = {
7777
componentInit() {

general/app/development/plugins-development-guide/index.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ As we have seen in the first example, the extension mechanism used in the app is
111111

112112
Now you should have a basic idea of how Site Plugins work in the app. If you want to continue learning, you can keep reading this guide. When you are ready, you can check out the [Examples](./examples/index.md) page for some step-by-step guides of common scenarios; or you can directly check out the [API Reference](./api-reference.md) for a comprehensive list of all the APIs and options available in Site Plugins.
113113

114+
## Files location
115+
116+
To ensure your plugin code is organized and passes the specific linting required for the Moodle App, you should place your files in the following directories within your plugin:
117+
118+
| File / Folder | Purpose |
119+
|-----------------------------|----------------------------------------------------------------------------------------|
120+
| `db/mobile.php` | Configuration file to register the mobile support and define the app areas to extend. |
121+
| `classes/output/mobile.php` | The main PHP class containing the logic for the mobile implementation. |
122+
| `js/mobileapp/` | This folder should contain all the JavaScript files intended for the mobile app. |
123+
| `templates/mobileapp/` | This folder should contain all the Mustache templates intended for the mobile app. |
124+
125+
:::note Notice
126+
Currently, the linting for mobile app templates is disabled to avoid throwing warnings with Angular, Ionic or Moodle app custom directives. This will be improved in the future.
127+
:::
128+
114129
## Rendering UI
115130

116131
Most handlers will render some custom UI using the `method` property in their configuration. They will return some templates in the [content response](./api-reference.md#content-responses), and the templates will be treated differently depending on the handler.
@@ -125,7 +140,7 @@ public static function mobile_course_view($args) {
125140
'templates' => [
126141
[
127142
'id' => 'main',
128-
'html' => $OUTPUT->render_from_template('local_hello/greeting', ['name' => 'John']),
143+
'html' => $OUTPUT->render_from_template('local_hello/mobileapp/greeting', ['name' => 'John']),
129144
],
130145
],
131146
'otherdata' => [
@@ -135,7 +150,7 @@ public static function mobile_course_view($args) {
135150
}
136151
```
137152

138-
```html handlebars title="template in templates/greeting.mustache"
153+
```html handlebars title="template in templates/mobileapp/greeting.mustache"
139154
{{=<% %>=}}
140155
<!-- This will render "Hello, John Doe" in the app -->
141156
<h1 class="text-center">Hello, <% name %> {{ CONTENT_OTHERDATA.surname }}</h1>

0 commit comments

Comments
 (0)