Skip to content

Commit

Permalink
Merge branch 'MDL-77182-master' of https://github.com/ferranrecio/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Feb 23, 2023
2 parents baae0cd + 135c8a9 commit d6c9b9e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions admin/settings/development.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
15 changes: 15 additions & 0 deletions lib/classes/output/mustache_filesystem_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<!-- template(PHP): $name -->" . parent::load($name) . "<!-- /template(PHP): $name -->";
}
return parent::load($name);
}
}
5 changes: 4 additions & 1 deletion lib/classes/output/mustache_template_source_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ public function load(
string $themename,
bool $includecomments = false
) : string {
global $CFG;
// Get the template source from the callback.
$source = ($this->gettemplatesource)($component, $name, $themename);

// Remove comments from template.
if (!$includecomments) {
$source = $this->strip_template_comments($source);
}

if (!empty($CFG->debugtemplateinfo)) {
return "<!-- template(JS): $name -->" . $source . "<!-- /template(JS): $name -->";
}
return $source;
}

Expand Down

0 comments on commit d6c9b9e

Please sign in to comment.