mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-77182 core: add debug template info setting
A new developer setting that adds comments in the page HTML specifying which template is used to render each part of the page. It can be set form the site admin development tab and it is stored as $CFG->debugtemplateinfo.
This commit is contained in:
parent
8503f2cfd8
commit
135c8a999c
@ -51,6 +51,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
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).
|
||||
|
@ -483,6 +483,8 @@ $string['debugsqltrace100'] = 'Show full stack trace';
|
||||
$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.';
|
||||
|
@ -65,4 +65,19 @@ class mustache_filesystem_loader extends \Mustache_Loader_FilesystemLoader {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +88,7 @@ class mustache_template_source_loader {
|
||||
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 @@ class mustache_template_source_loader {
|
||||
if (!$includecomments) {
|
||||
$source = $this->strip_template_comments($source);
|
||||
}
|
||||
|
||||
if (!empty($CFG->debugtemplateinfo)) {
|
||||
return "<!-- template(JS): $name -->" . $source . "<!-- /template(JS): $name -->";
|
||||
}
|
||||
return $source;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user