MDL-59380 fragments: Include js from templates

Mustache templates containing {{#js}} blocks are not returned via the
fragments API. This is because the requirements manager is assigned when the renderer is created
and not updated by the call to start collecting page requirements.
This commit is contained in:
Damyon Wiese
2017-06-27 13:35:40 +08:00
parent 7624f86fb2
commit 4197baf775
2 changed files with 7 additions and 7 deletions
@@ -34,16 +34,16 @@ namespace core\output;
*/
class mustache_javascript_helper {
/** @var page_requirements_manager $requires - Page requirements manager for collecting JS calls. */
private $requires = null;
/** @var moodle_page $page - Page used to get requirement manager */
private $page = null;
/**
* Create new instance of mustache javascript helper.
*
* @param page_requirements_manager $requires Page requirements manager.
* @param moodle_page $page Page.
*/
public function __construct($requires) {
$this->requires = $requires;
public function __construct($page) {
$this->page = $page;
}
/**
@@ -54,6 +54,6 @@ class mustache_javascript_helper {
* @param \Mustache_LambdaHelper $helper Used to render the content of this block.
*/
public function help($text, \Mustache_LambdaHelper $helper) {
$this->requires->js_amd_inline($helper->render($text));
$this->page->requires->js_amd_inline($helper->render($text));
}
}
+1 -1
View File
@@ -89,7 +89,7 @@ class renderer_base {
$loader = new \core\output\mustache_filesystem_loader();
$stringhelper = new \core\output\mustache_string_helper();
$quotehelper = new \core\output\mustache_quote_helper();
$jshelper = new \core\output\mustache_javascript_helper($this->page->requires);
$jshelper = new \core\output\mustache_javascript_helper($this->page);
$pixhelper = new \core\output\mustache_pix_helper($this);
// We only expose the variables that are exposed to JS templates.