-
Improvement
-
Resolution: Fixed
-
Minor
-
4.2
-
MOODLE_402_STABLE
-
MOODLE_402_STABLE
-
MDL-77182-master -
-
1
-
HQ 2023 Sprint i1.1 Moppies
There is a particular developer setting called "debugstringids" which forces the injection of the string ID to all string. However, there is no easy way to identify which template is responsible for a specific page part.
The idea is to implement a new developer setting called "debugtemplatenames" which adds HTML comments when a mustache file is rendered.
For example, imagine the "core/mytemplate" template:
<p>This is an example</p>
|
With the setting the resulting HTML could be:
1) If it is rendered using PHP:
<!-- template(PHP): core/mytemplate --><p>This is an example</p><!-- /template(PHP): core/mytemplate -->
|
2) If it is rendered using JS:
<!-- template(JS): core/mytemplate --><p>This is an example</p><!-- /template(JS): core/mytemplate -->
|
Differentiating between PHP and JS is entirely optional, but because the loading workflow is different, it could be easy to do.
Of course, adding those comments can break some frontend JS, but as a tool to identify templates will be helpful.
Technical shaping
Template rendering is quite complex. However, I identified two main files involved in the template content loading :
- lib/classes/output/mustache_template_source_loader.php used form the PHP rendering
- lib/classes/output/mustache_filesystem_loader.php used form js load template webservice
In the mustache_template_source_loader it is possible to path the load method to add the information.
public function load( |
string $component,
|
string $name,
|
string $themename,
|
bool $includecomments = false |
) : string {
|
global $CFG;
|
// Get the template source from the callback. |
$source = ($this->gettemplatesource)($component, $name, $themename); |
if (!$includecomments) { |
$source = $this->strip_template_comments($source); |
}
|
if ($CFG->debugtemplatenames) { |
result = "<!-- /template(JS): $name -->" . $result . "<!-- /template(JS): $name -->" |
}
|
return $source"; |
}
|
In the mustache_filesystem_loader is possible to override the original load function with something like:
public function load($name) { |
global $CFG;
|
$result = parent::load($name);
|
if ($CFG->debugtemplatenames) { |
result = "<!-- /template(PHP): $name -->" . $result . "<!-- /template(PHP): $name -->" |
}
|
return $result; |
}
|
- caused a regression
-
MDL-80593 All modals break because of config option debugtemplateinfo
-
- Closed
-
-
MDL-78131 filemanager.js: Uncaught TypeError - on course edit page, when debugtemplateinfo=true
-
- Closed
-
-
MDL-79147 Remove return type hinting from core\output\mustache_filesystem_loader::load
-
- Closed
-
-
MDL-80474 'Add a block' doesn't work if debugging is set to DEVELOPER and 'Show template information' is set to YES
-
- Closed
-
- has been marked as being related by
-
MDL-77181 Help with debugging errors in Mustache templates by making it easy to find the template .mustache file which caused the error
-
- Open
-