ez.no / ezpublish / documentation / customization / custom design / override templates
These documentation pages are no longer maintained. Please visit the new documentation site.
We usually want to have different templates based on the class we are viewing. If we are viewing a folder we would probably like to list all content of the folder, but if we are viewing an article we would like to show that specific article. To do this we use override templates.
Override templates are defined in the override.ini(.append) configuration file and placed in the override directory in the design directory. Usually this will be done specific for each site access and the override file for the site access should then be used. Overrides can be set to be activated based on things like the current node, object, class or section.
The override template settings can also be defined in the admin interface (Setup -> Templates), we will however use the configuration file in this documentation.
The override.ini(.append) file contains one block for each override. A block contains information about which template to override, filename, placement and how to override. Each block starts with an uniqe block identifier (e.g. [musicfolder]), which could be choosen by the user.
Example:
[musicfolder] Source=node/view/full.tpl MatchFile=musicfolder.tpl Subdir=templates Match[class]=1 Match[section]=4 [welcomearticle] Source=node/view/full.tpl MatchFile=welcomearticle.tpl Subdir=templates Match[node]=42 [NewsTree] Source=node/view/full.tpl MatchFile=news_article.tpl Subdir=templates Match[class]=2 Match[url_alias]=news
This configuration creates three override cases, all will override node/view/full.tpl based on different settings. The first override template is named musicfolder.tpl and is located in override/templates/. This template will be used if someone is viewing an object with class ID 1 in section 4. The next override is named welcomearticle.tpl and will only be used when someone is viewing the node with ID 42.
The last override overrides the full view of class 2 in all nodes under the node having "news" in its url alias.
Notice: In order to use your new override configuration ini file(s), please do not forget to clear override cache files under var/cache/override, otherwise you will only get the outdated version of the template file(s). Some useful clues can be found here.
|
Setting |
Description |
|---|---|
|
Source |
Name of the template we override |
|
MatchFile |
Name of the override template |
|
Subdir |
Overrides if node has class ID |
|
Match[object] |
Matches the object ID |
|
Match[node] |
Matches the node ID |
|
Match[parent_node] |
Matches on the parent node ID |
|
Match[class] |
Matches on the class ID |
|
Match[class_identifier] |
Matches on the class identifier ( added in 3.4 ) |
|
Match[attribute_identifier] |
Matches on the class attribute identifier ( added in 3.4 ) |
|
Match[view_offset] |
Matches on the current offset in a list |
|
Match[section] |
Matches the section ID |
|
Match[classification] |
Matches the classification for eZXMLText tags, see here for more |
|
Match[depth] |
Matches on the depth of the current node |
|
Match[class_group] |
Matches class group id, available from 3.5, optional |
|
Match[url_alias] |
Matches the subtree set by the url alias. |
All ways of matching can be combined to only override the nodes you want.
If no overrides are found for the current node the standard file (node/view/full.tpl in this example) will be used. If this file is missing as well then the system will use the templates in the standard design.
At the time of writing, subdirs within the subdir do not work, they are ignored, so
#will work Subdir=templates
works, but specifying a nested subdir will not work as in the follwing example
#will not work Subdir=templates/catalogs
You can specify the subdir with the MatchFile instead:
[medium_image_catalog] Source=node/view/medium_class_4.tpl MatchFile=catalogs/medium_image_catalog.tpl Subdir=templates Match[class]=4 Match[section]=9 Match[node]=67543322
If you need to use the same template file for several of your classes the new template system now makes this easy. Previous to 3.1 you had to either make copies of your file or use symbolic links.
With 3.1 the following example code allow classes 20 and 21 to display using the template file 'full_article.tpl'
[full_article] Source=node/view/full.tpl MatchFile=node/full_article.tpl Subdir=templates Match[class]=20 [full_news_article] Source=node/view/full.tpl MatchFile=node/full_article.tpl Subdir=templates Match[class]=21
Viewing your full.tpl from the templateview function within the admin will confirm that full.tpl has been overridden in the way you expect.
The order within overide.ini(.append) is important for matching the override templates. The file is read sequentially from top to down, first match will be taken. In general the more specifiy template overrides should be placed above the less specific ones. If you like to override one class in general, but you want to override it within one section with a different template, place the more specific match (for the section+class) above the less specific (only class).
For Example:
[folder_full_section_12] Source=node/view/full.tpl MatchFile=folder_full_section_12.tpl Subdir=templates Match[class]=1 Match[section]=12 [folder_full] Source=node/view/full.tpl MatchFile=folder_full.tpl Subdir=templates Match[class]=1
If both rules are swaped, the [folder_full] is used for all folders and [folder_full_section_12] will never match.
Comments
what should be written in url_alias: alias of node or alias of parent node
esu vytis
Monday 04 April 2005 10:41:32 am
So, what i should write in overrides.ini
[Line_view_article]
...
Match[url_alias]=ALIAS_OF_FOLDER
or
Match[url_alias]=ALIAS_OF_EVERY_ARTICLE
tabs within block definitions
Carl Heaton
Wednesday 09 March 2005 11:10:57 am
Why is there an "override/templates" directory?
András Puiz
Tuesday 22 June 2004 3:19:22 am
Is there any way to.....
Vaskin Kissoyan
Friday 18 June 2004 6:32:20 pm
BUG in eZ publish 3.4.0
Dmitry T
Wednesday 16 June 2004 9:07:08 pm
!!! override.ini.append !!!
but used first
!!! override.ini.append.php !!!
Example for Match[depth]?
Silke Fox
Monday 03 May 2004 4:17:42 pm
It sounds quite useful to me, but I'm not sure how it works exactly... ;)
Is it the total depth of a node (starting from node 2)?
Or within a sitemap the depth from the current node to its child node...?
Any hints are welcome...
Silke
how to check which section that was accessed
akiL Mussa
Monday 22 March 2004 3:05:15 pm
Re: Override pagelayout.tpl
jamie harbison
Saturday 14 February 2004 3:22:22 am
How would i write that switch that inserts the correct/desired banner/logo and stylesheet? And if i did want to override the pagelayout.tpl for a section for some reason, how would i do that
Thanks very much!
Re: Override pagelayout.tpl
Balazs Halasy
Monday 09 February 2004 9:53:16 am
Balazs
Override pagelayout.tpl
jamie harbison
Monday 09 February 2004 5:15:21 am
Why numeric ID ?
antonio lombrano
Monday 19 January 2004 9:40:11 am
In other words.....the code is not portable. What a programmer writes must be checked and eventually changed before installing it on another ezpublish installation. All medium-large environments has got three server: the development server, the staging server and the production server. A programmer must check and change his code three times. I think it would be much better working with literal ID, defined by the programmers and which never changes. Only one version of code which works on all environments. It should not be that difficult.
One important notice
Christian Lundvang
Wednesday 03 September 2003 2:37:23 pm
Example 1. Will work:
[full_node_2]
Source=node/view/full.tpl
MatchFile=node/view/full_node_2.tpl
Subdir=templates
Match[node]=2
[full_class_1]
Source=node/view/full.tpl
MatchFile=node/view/full_class_1.tpl
Subdir=templates
Match[class]=1
Example 2. Will NOT work:
[full_class_1]
Source=node/view/full.tpl
MatchFile=node/view/full_class_1.tpl
Subdir=templates
Match[class]=1
[full_node_2]
Source=node/view/full.tpl
MatchFile=node/view/full_node_2.tpl
Subdir=templates
Match[node]=2
In both examples full_node_2.tpl is an folder.
It seems to be an error...
Thomas Nunninger
Sunday 27 July 2003 9:40:59 pm
Does this make sense in the context of the rest...
Order of overrides
Ben Pirt
Thursday 24 July 2003 1:26:49 pm
Perhaps a prioritisation should occur in this ini file, regardless of the order of placement?
i.e. in order of priority
node > parent_node > class
or something like that?