From 3d185facebac3729087480912cb0c4d811af1220 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Tue, 27 Jun 2017 13:18:36 +0800 Subject: [PATCH] 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. --- lib/classes/output/mustache_javascript_helper.php | 12 ++++++------ lib/outputrenderers.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/classes/output/mustache_javascript_helper.php b/lib/classes/output/mustache_javascript_helper.php index 7ba9b2acec1..5644b4b6813 100644 --- a/lib/classes/output/mustache_javascript_helper.php +++ b/lib/classes/output/mustache_javascript_helper.php @@ -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)); } } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 0aae68d5ccb..5460868461d 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -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); $shortentexthelper = new \core\output\mustache_shorten_text_helper(); $userdatehelper = new \core\output\mustache_user_date_helper();