The template override system
The template override system lets a design use another template than the default in situations you describe: a template for articles, another for one particular node, another for everything in a section. A rule names the template it replaces, the template to use instead, and the conditions under which it applies. Rules work for every template that is loaded through the design, including those included with {include uri='design:...'}, but they are most useful for node templates, because the content view offers the most conditions.
A rule
[full_article] Source=node/view/full.tpl MatchFile=full/article.tpl Subdir=templates Match[class_identifier]=article Match[section]=1
| Key | Meaning |
|---|---|
| [full_article] | The name of the rule, unique among all rules of the siteaccess. |
| Source | The template that is replaced, as the code asks for it, relative to templates/. |
| MatchFile | The template used instead, relative to override/templates/ of a design. |
| Subdir | Written as templates by convention; the kernel looks for MatchFile below override/templates/. |
| Match[<key>] | A condition. A rule can have several; all of them must hold. A rule without conditions always applies. |
| Priority | Optional. The order in which rules are tried (see below). |
The file named in MatchFile is looked up in override/templates/ of each design of the chain, in the design order. When no design has it, the debug output shows the error "Custom match file: path ... not found in any resource", followed by every path that was tried.
Where the rules go
- settings/siteaccess/<siteaccess>/override.ini.append.php: rules of one siteaccess. This is the usual place, and the file the Template Editor writes.
- settings/override/override.ini.append.php: rules for every siteaccess.
- extension/<extension>/settings/override.ini.append.php, or below settings/siteaccess/<siteaccess>/ of the extension: rules that come with an extension's design.
Never edit settings/override.ini, the file of the kernel; it only holds a commented example.
Conditions
The content view sets these match keys for a node template (kernel/classes/eznodeviewfunctions.php):
| Key | Matches |
|---|---|
| object, node, parent_node | the object id, the node id, the parent's node id |
| remote_id, node_remote_id, parent_node_remote_id, parent_object_remote_id | remote ids of the object, the node, the parent node and its object |
| class, class_identifier | the class id or identifier, such as article |
| parent_class, parent_class_identifier | the class of the parent's object |
| class_group | a class group of the class (when class group overrides are enabled) |
| section, section_identifier | the section of the object |
| state, state_identifier | an object state, such as ez_lock/not_locked |
| depth | the node's depth in the tree |
| url_alias | the start of the node's URL alias: news matches news and everything below it |
| viewmode, view_offset | the view mode, the offset view parameter |
| navigation_part_identifier | the navigation part, mostly for the administration interface |
| persistent_variable | the persistent variable, when a template set one |
| layout | the layout of layout/set (print and others); empty without one (6.0.15) |
A key whose value is a list (state, class_group) matches when the condition's value is in the list. A condition on a key the view does not set never holds, which is why system templates have few usable conditions. The keys of every view are listed in Template override conditions.
Which rule wins
For one Source template, Exponential tries the rules with conditions in order and uses the first whose conditions all hold. The order is:
- Rules with a Priority, lowest number first.
- Rules without a Priority, in the order the settings files define them.
A rule without conditions is not tried in that order: it replaces the default template, and is used when no rule with conditions holds. If no rule holds and there is no rule without conditions, the Source template itself is used, from the first design that has it.
So put the most specific rules first: a rule for one node or one object before the rule for its class. Otherwise the class rule wins and the node rule is never reached. The Template Editor writes Priority values for you and lets you reorder rules by drag and drop; see The Template Editor.
After a change
The rules are compiled into the template override cache. After adding or changing a rule in a file, or adding a template at a new path, clear it together with the INI and template caches:
php bin/php/ezcache.php --clear-tag=ini php bin/php/ezcache.php --clear-tag=template php bin/php/ezcache.php --clear-id=content
The tag template covers the compiled templates, the override cache and the cache blocks. The last line expires the content view cache, so pages that are already cached use the new rule too. Add --allow-root-user when you run it as root. A worked example with four rules: Template override example. To see which rule answered on a page, use template path comments (Debugging templates).
In this section
- Template override example An example of Exponential 6 template overrides: rules for the front page, folders, articles and products, with their templates.
- Please make it easier to understand / The template overri... Exponential Documentation
- Possible override combinations / The template override sy... Exponential Documentation
Contributors
- Balazs Halasy
- Geir Arne Waaler Maintainer
- Sarah Haïm-Lubczanski Maintainer
- Adam Commenter
- Marc Boon Commenter
- Pike Commenter
- Ajay Tyagi Commenter
- Heiner Commenter
- Svitlana Shatokhina Commenter
- Steven Commenter
- Graham Brookins Updated Maintainer
Comments (7 historical)
Written by readers of the earlier documentation sites, kept as they were.
Please make it easier to understand
Adam ·
Hello,
I want to learn how to override a template...
Great, I've created the new folder...created a duplicate of pagelayout.tpl....
I can see this line saying...
"The template overrides must be defined in the "override.ini.append.php" file of a siteaccess".
Why can't i find anything that tells me where to create override.ini.append.php.
It also doesn't explain if these .ini files are needed per template or if you have one file that handles the whole lot. It also doesn't tell me if this can be done via admin, rather than manually.
It also doesn't tell me how to create overrides via the admin area as I see a "New Override" option.
I'm really confused...
It's like you're telling me steps 3 and 4 with the assumtion that I know 1 and 2 like yourself....
Hope you can help,
Thanks
Re: Please make it easier to understand
Marc Boon ·
"The template overrides must be defined in the "override.ini.append.php" file of a siteaccess".
This means that the file should be created in the /siteaccess/your_site/ folder, next to the site.ini.append.php file, which resides in the same folder.
So, for every site access, you have one override.ini.append.php file.
The templates that you create to override the standard templates, are placed in the /design/your_design/override/templates folder (create it if nescessary).
Custom pagelayout templates however, can just be placed in the design/your_design/templates folder. There is no need to create a override.ini.append.php for those. If templates exist in the /design/your_design/templates folder, they will always be used instead of the /design/standard/templates folder.
See also: <url>http://ez.no/doc/ez_publish/techn...igns/design_combinations</url>
The special thing with override templates is that they can *conditionally* override default templates, only if cetain conditions are met, like node id or object class, using the Match specifier.
Re: Re: Please make it easier to understand
Pike ·
"The template overrides must be defined in the "override.ini.append.php" file of a siteaccess".
This means that the file should be created in
[exponentialdir]/settings/siteaccess/[yoursitedir]/override.ini.append.php
How to customize the template
Ajay Tyagi ·
Hi all,
could you please tell me, How can i override the various .tpl sothat i can add more images and menus in head part, and like that in various .tpl like footer.tpl .
if i have a web page then how can i make the templates from that page????
Possible override combinations
Heiner ·
I dont know, if all of them are still working ....
Re: Possible override combinations
Svitlana Shatokhina ·
see http://ez.no/doc/ez_publish/techn...ference/template_override_conditions
Where are the pictures?
Steven ·
Where are the pictures in this article?