diff --git a/admin/settings/development.php b/admin/settings/development.php index 88d6df729c37e..207296a792af5 100644 --- a/admin/settings/development.php +++ b/admin/settings/development.php @@ -51,6 +51,7 @@ 100 => new lang_string('debugsqltrace100', 'admin')))); $temp->add(new admin_setting_configcheckbox('debugvalidators', new lang_string('debugvalidators', 'admin'), new lang_string('configdebugvalidators', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('debugpageinfo', new lang_string('debugpageinfo', 'admin'), new lang_string('configdebugpageinfo', 'admin'), 0)); + $temp->add(new admin_setting_configcheckbox('debugtemplateinfo', new lang_string('debugtemplateinfo', 'admin'), new lang_string('debugtemplateinfo_desc', 'admin'), 0)); $ADMIN->add('development', $temp); // "Profiling" settingpage (conditionally if the 'xhprof' extension is available only). diff --git a/lang/en/admin.php b/lang/en/admin.php index bc34156ec17b7..7e8e79f63e0f7 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -483,6 +483,8 @@ $string['debugsqltrace_desc'] = 'If enabled, a partial or full PHP stack trace is added into the SQL as a comment.'; $string['debugstringids'] = 'Show origin of languages strings'; $string['debugstringids_desc'] = 'If enabled, language string components and identifiers are displayed when ?strings=1 or &strings=1 is appended to the page URL.'; +$string['debugtemplateinfo'] = 'Show template information'; +$string['debugtemplateinfo_desc'] = 'If enabled, templates used for rendering are shown as comments in the page HTML. Use for temporary debugging only, as it produces HTML validation errors and could break some page scripts.'; $string['debugvalidators'] = 'Show validator links'; $string['defaultcity'] = 'Default city'; $string['defaultcity_help'] = 'A city entered here will be the default city when creating new user accounts.'; diff --git a/lib/classes/output/mustache_filesystem_loader.php b/lib/classes/output/mustache_filesystem_loader.php index e79b479fed500..6c1e1603cab26 100644 --- a/lib/classes/output/mustache_filesystem_loader.php +++ b/lib/classes/output/mustache_filesystem_loader.php @@ -65,4 +65,19 @@ protected function getFileName($name) { protected function shouldCheckPath() { return true; } + + /** + * Load a Template by name. + * + * @param string $name the template name + * @return string Mustache Template source + */ + public function load($name): string { + global $CFG; + if (!empty($CFG->debugtemplateinfo)) { + // We use many templates per page. We don't want to allocate more memory than necessary. + return "" . parent::load($name) . ""; + } + return parent::load($name); + } } diff --git a/lib/classes/output/mustache_template_source_loader.php b/lib/classes/output/mustache_template_source_loader.php index 39d6bd8ebc315..471bc0c6feb3b 100644 --- a/lib/classes/output/mustache_template_source_loader.php +++ b/lib/classes/output/mustache_template_source_loader.php @@ -88,6 +88,7 @@ public function load( string $themename, bool $includecomments = false ) : string { + global $CFG; // Get the template source from the callback. $source = ($this->gettemplatesource)($component, $name, $themename); @@ -95,7 +96,9 @@ public function load( if (!$includecomments) { $source = $this->strip_template_comments($source); } - + if (!empty($CFG->debugtemplateinfo)) { + return "" . $source . ""; + } return $source; }