diff --git a/docs/guides/templates/index.md b/docs/guides/templates/index.md index e83e4c2c7..37ea64d4c 100644 --- a/docs/guides/templates/index.md +++ b/docs/guides/templates/index.md @@ -10,7 +10,7 @@ description: A guide to the features and use of Mustache templating in Moodle. Moodle makes use of the [Mustache](https://mustache.github.io) template system to render most of its HTML output, and in some other cases too. -Templates are defined as plain text, which typically includes HTML, and a range of Mustache tags and placeholders. The Mustache placeholders are replaced with actual values during the render of the page. Mustache templates can be rendered both server-side in PHP, and client-side using JavaScript. Themes can overrides the templates defined in other components if required. +Templates are defined as plain text, which typically includes HTML, and a range of Mustache tags and placeholders. The Mustache placeholders are replaced with actual values during the render of the page. Mustache templates can be rendered both server-side in PHP, and client-side using JavaScript. Themes can override the templates defined in other components if required.
A simple example diff --git a/versioned_docs/version-4.1/guides/templates/index.md b/versioned_docs/version-4.1/guides/templates/index.md index c4615b30a..37ea64d4c 100644 --- a/versioned_docs/version-4.1/guides/templates/index.md +++ b/versioned_docs/version-4.1/guides/templates/index.md @@ -10,7 +10,7 @@ description: A guide to the features and use of Mustache templating in Moodle. Moodle makes use of the [Mustache](https://mustache.github.io) template system to render most of its HTML output, and in some other cases too. -Templates are defined as plain text, which typically includes HTML, and a range of Mustache tags and placeholders. THe Mustache placeholders are replaced with actual values during the render of the page. Mustache templates can be rendered both server-side in PHP, and client-side using JavaScript. Themes can overrides the templates defined in other components if required. +Templates are defined as plain text, which typically includes HTML, and a range of Mustache tags and placeholders. The Mustache placeholders are replaced with actual values during the render of the page. Mustache templates can be rendered both server-side in PHP, and client-side using JavaScript. Themes can override the templates defined in other components if required.
A simple example @@ -486,7 +486,7 @@ Templates.renderForPromise('block_looneytunes/profile', context) .catch((error) => displayException(error)); ``` -Under the hood, this does a few clever things for us. It loads the template via an AJAX call if it was not cached. It finds any missing lang strings in the template and loads them in a single AJAX request. It split the JS from the HTML and returns us both in easy to use way. Read on for how to nicely deal with that `js` parameter. +Under the hood, this does a few clever things for us. It loads the template via an AJAX call if it was not cached. It finds any missing lang strings in the template and loads them in a single AJAX request. It splits the JS from the HTML and returns both in an easy to use way. Read on for how to nicely deal with that `js` parameter. ## Templates requiring JavaScript @@ -661,6 +661,7 @@ In PHP you have access to the `$CFG` object to allow access to properties. Musta ``` The properties available on the `globals.config` object are the same as normally exposed for JavaScript; these are gathered from `get_config_for_javascript()` function in `lib/outputrequirementslib.php`. +This object is only available when using client-side Mustache rendering in JavaScript; it is not added to templates rendered with the PHP Mustache engine. ## Core templates diff --git a/versioned_docs/version-4.3/apis/subsystems/output/index.md b/versioned_docs/version-4.3/apis/subsystems/output/index.md index 4bf1cb102..ff25c1013 100644 --- a/versioned_docs/version-4.3/apis/subsystems/output/index.md +++ b/versioned_docs/version-4.3/apis/subsystems/output/index.md @@ -209,10 +209,10 @@ This is the mustache template for this demo. It uses some bootstrap classes dire ## Output Functions -This section tries to explain a bit how dynamic data should be sent from Moodle to the browser in an organised and standard way. +This section explains how dynamic data should be sent from Moodle to the web browser in an organised and standard way. :::important -Obviously it's possible to have your own output methods but, thinking that you are going to share your code (yep, this is an OpenSource project!) and in the collaborative way we try to build and maintain the system every day, it would be really better to follow the basic guidelines explained below. +It is possible to have your own output methods but, thinking that you are going to share your code (yep, this is an OpenSource project!) and in the collaborative way we try to build and maintain the system every day, it would be really better to follow the basic guidelines explained below. By using them you will be helping to have better, more secure and readable code. Spend some minutes trying to understand them, please! ::: @@ -223,6 +223,8 @@ For each of the functions below we'll try to explain when they should be used, e ### String formatting functions +The `format_string` and `format_text` functions should always be used when preparing the output of information. They may also be used to process information before it is stored in the database however, filters should only be applied at output. For example, language filters must only be applied as the content is prepared for output because we don't yet know the user's preferred language. + #### p() and s() ```php @@ -230,61 +232,74 @@ function s($var, $strip=false) function p($var, $strip=false) ``` -These functions share the same code, so they will be explained together. The only difference is that `s()` returns the string, while `p()` prints it directly. +The only difference between these two functions is that `s()` returns the string, while `p()` prints it directly. These functions should be used to: -- print all the **values of form fields** like `` or `