Lesson 3.4: Finding the template behind a page
The most common question of a template developer is "which file made this?", and the second is "why not mine?".
This lesson gives learners a routine that answers both in minutes: template path comments, the list of used
templates, exp:ini where for override rules, and the syntax checker.
At a glance
| Course | Developers |
| Module | Module 3: Designs, overrides and debugging |
| Duration | 45 minutes (15 presenting, 30 exercise) |
| Level | Intermediate |
| Audience | Developers and template builders |
| Prerequisites | Lesson 3.2 and Lesson 1.3 |
Learning objectives
After this lesson, learners can:
- read
STARTandSTOPcomments in the page source, including the original name in brackets; - read the list of used templates in the debug output and follow its edit links;
- find every file that defines an override block with
exp:ini where; - check templates with
eztemplatecheck.phpand read its error messages; - work through a checklist when an override does not apply.
Trainer's notes
How to present it
Sources: Template path comments and Templates and design, part 7.
Path comments (4 minutes). With
[TemplateSettings] ShowTemplatePathComments=enabled, every template's output is wrapped in<!-- START ... -->and<!-- STOP ... -->. When an override answered, the original name follows in brackets:<!-- START .../full/article.tpl (node/view/full.tpl) -->reads "the filearticle.tplanswered the requestnode/view/full.tpl". Development only: the comments break JSON, XML and RSS output.Used templates (3 minutes). With
ShowUsedTemplates=enabledthe debug output lists every template of the page, the requested one and the one used. In the administration, the Quick settings box has the switches Debug output, Template debug, Inline template debug and List of used templates for the current siteaccess.The checklist (5 minutes). Project this table:
Question Do this Which file wrote it? Path comments Why this file and not mine? Check Source,MatchFile,Match[...];exp:ini where override.ini/<block>/MatchFile <sa>Is the syntax right? php bin/php/eztemplatecheck.php <file>Still the old output? Clear ini,template-override,template,contentWhich templates, how long, how many queries? The Exp Debug bar: templates, timing, SQL The checker (3 minutes).
eztemplatecheck.phptakes a file, a directory or-s<siteaccess>for all templates of a siteaccess. A wrong closing tag reads "Unterminated tag ... does not match tag ...".
Common questions
Can I switch path comments on for one siteaccess only? Yes: exp:ini set site.ini/TemplateSettings/ShowTemplatePathComments enabled siteaccess:<sa>.
The edit links of the used templates open the wrong editor. [DebugSettings] UsedTemplateEditUrl sets the
link as a sprintf() format, for example to the administration's editor
(Templates and design, part 7).
What about operator warnings? A warning such as "Operator 'my_operator' has no default value for parameter 'length'" names the template and line; it is shown once per compile.
Pitfalls
- Comments in production. Switch path comments off again after the lesson.
- Searching the compiled cache. Compiled templates under
var/are not the files to edit. Always edit the.tplnamed in the comment. - An override in a different siteaccess. The rule was written for
sitebut the page is served by another siteaccess.exp:ini wherewith the right siteaccess name shows it.
Hands-on exercise
On the development installation, with the overrides of lesson 3.2 in place.
Switch on path comments for your public siteaccess and clear the template cache:
php bin/php/console exp:ini set site.ini/TemplateSettings/ShowTemplatePathComments enabled siteaccess:<sa> php bin/php/ezcache.php --clear-tag=ini php bin/php/ezcache.php --clear-tag=templateOpen an article on the site, view the page source, and search for
START. Find the comment with(node/view/full.tpl)and write down which file answered.Find the template of the page's header or footer the same way.
In the debug bar, open the list of used templates and find the same two files.
List the files that define your override block:
php bin/php/console exp:ini where override.ini/mysite_full_article/MatchFile <sa>.Break the rule on purpose: set
Match[class_identifier]toartcle(a typo) withexp:ini set, clear theini,template-overrideandcontentcaches, and reload. Use the checklist to find the cause, then fix it.Break the template on purpose: change one
{/if}into{/foreach}and runphp bin/php/eztemplatecheck.php extension/mysite_hello/design/<design>/override/templates/full/mysite_article.tpl. Fix it.Check all templates of your extension at once:
php bin/php/eztemplatecheck.php extension/mysite_hello/design/.Switch path comments off again (
disabled) and clear the template cache.
Expected result
- Step 2: a comment such as
<!-- START extension/mysite_hello/design/<design>/override/templates/full/mysite_article.tpl (node/view/full.tpl) -->. - Step 5: the extension's siteaccess file and the value in effect.
- Step 6: the page falls back to another template; after the fix the course line is back.
- Step 7:
Template file invalidwith the line; step 8 ends without errors after the fix. - The trainer checks that each learner can explain the bracket in step 2.
Quiz
- What does
(node/view/full.tpl)at the end of aSTARTcomment tell you? - Which command lists every file that defines an override block, in load order?
A.
exp:ini getB.exp:ini whereC.eztemplatecheck.phpD.ezcache.php --list-ids - Name three reasons an override does not apply.
- Why must path comments be off for a feed or a JSON view?
- Which box of the administration switches debug output and the list of used templates for the current siteaccess?
Answers
- An override answered; the file named before the bracket replaced the requested
node/view/full.tpl. - B.
exp:ini where override.ini/<block>/MatchFile <sa>. - A condition does not match (typo, wrong class); the rule is in another siteaccess; caches were not cleared; a rule with a higher priority matches first; the template file is not in a design of the chain.
- They add HTML comments to the output, which breaks JSON, XML and RSS.
- Quick settings, with Debug output and List of used templates.
Further reading
- Template path comments: format, overrides and limits.
- The Exp Debug bar: templates, timing and SQL tabs.
- Debug output improvements: what changed in the debug output.
Related pages
- Module 3: Designs, overrides and debugging
- Developers: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.