Project 3: a template override
In this project you change how one kind of content looks on the site, without touching any file you do not own. You do it twice: once with the template editor in the administration, once as files you keep in Git. The steps follow Templates and design.
Contents
At a glance
| Level | Intermediate |
| Time | About 3 hours |
| Paths | Developer, designer |
| Prerequisites | A terminal on your study site; Learning the template language; project 1 is useful |
Goal
A full view for one content class (your "Club event" from project 1, or Article) that shows the title, one or more attributes and a list of the item's siblings, applied only to that class, kept as files in your own Git repository.
Before you start
Read Templates and design, parts 1 to 6, and Understanding siteaccesses and settings.
Tasks
- Find your design. Run
php bin/php/console exp:ini where site/DesignSettings/SiteDesign site(use the siteaccess of the page you look at). Note the design name from theIn effect:line (Templates and design). - See which template answers. Switch on the template path comments for your public siteaccess, clear the
template cache, open an item of your class, and search the page source for
START(Templates and design). Note the template that renders the full view. - Click path. In Design > Template Editor, open
node/view/full.tplof your design, press New override, choose Default copy, enter the object ID of one item, and Create. Add a visible line, save, reload the item. Then remove the override again with Remove selected (Templates and design). - File path. Create the template in the override directory of your design, or better, in a design extension of
your own (Learning path: designer, step 7). Write an override rule in
override.ini.append.phpwithSource=node/view/full.tpl, yourMatchFile,Subdir=templates, andMatch[class_identifier]=<your class identifier>instead of a single object. - Write the template. Show the title with
{$node.name|wash}, at least one attribute withattribute_view_gui, and the list of siblings from the guide's example. Every printed value is escaped. - Check the syntax:
php bin/php/eztemplatecheck.php -s<siteaccess> <your file> --allow-root-user. Expected:Template file valid: <your file>(Templates and design). - Clear the caches once for the new template path (
template-override, the template tag and the content tag, as in the guide), and reload two items of your class and one item of another class. Only your class should change. - Switch the path comments off again and clear the template cache. They add markup to every template and must never stay on.
- Commit the template and the rule to your own repository.
Hand in
- The template file and the override rule.
- Screenshots: the page source with the
START ... (node/view/full.tpl)comment of your file; two items of your class and one of another class. - The output of the syntax check.
- A short report: why you matched by class and not by object, and what each line of the template does.
Rubric
Score the four common criteria of Grading your own work, and these checks (8):
- The design name was found with
exp:ini where, not guessed. - No file in
design/standard/was changed. - The override applies to the whole class and only to it.
- Every printed value uses
washor a view function. - The syntax check passes.
- The path comments are switched off at the end.
- The files are in the learner's own Git repository, without
settings/override/secrets. - The report explains
Source,MatchFile,SubdirandMatch.
Stretch goals
- Add a
lineview override for the same class and use it in a list withnode_view_gui ... view='line'. - Order two matching overrides with
Priorityand explain which wins (Template editor). - Read Template resources and overrides and draw the resolution of your template.
Related pages
- Study projects: overview
- Learning the template language
- Override basics
- 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.