Path

ez.no / ezpublish / documentation / customization / custom design / override templates


Override templates

These documentation pages are no longer maintained. Please visit the new documentation site.

Overriding templates

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.

override.ini

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.

Subdirs

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

Using the same template file for several classes

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.

Order within override.ini(.append)

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

i have folder "news" and some articles in it. And i want to display articles in different style from section.
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

EZP 3.5 won't parse block definitions which are prepended with tabs (other versions not tested)

Why is there an "override/templates" directory?

Apparently the admin interface for creating custom templates uses this one. But what's the difference between templates stored in "design/[MyDesign]/template/" and ones stored in "design/[MyDesign]/override/templates/"?

Is there any way to.....

Match on the class of the parent node?

BUG in eZ publish 3.4.0

New template write to

!!! override.ini.append !!!

but used first

!!! override.ini.append.php !!!

Example for Match[depth]?

Can anyone give an example for the Match[depth] setting?
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

How can I check which section that was accessed and do a switch that inserts the correct/desired banner/logo? How can I retrieve the section that was accessed?

Re: Override pagelayout.tpl


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

Yes, it is possible to override the pagelayout.tpl. However, if the only thing that you need to change is the banner/logo, then it is possible to do this without having to override the pagelayout itself. Simply check which section that was accessed and do a switch that inserts the correct/desired banner/logo (determined by the section).

Balazs

Override pagelayout.tpl

Is there any way to override the pagelayout.tpl for different sections? I need a different header image/stylesheet for each section (like in EZ2.2)

Why numeric ID ?

This is just my opinion, but I find annoying working with numeric ID, most of all because they've not been defined by the programmer, but they're automatically generated by the system.
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

Override of a certain node must be above classoverrides in the override.ini.appen-file.

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...

In the "Setting - Description" part it says that "Subdir" "Overrides if node has class ID".

Does this make sense in the context of the rest...

Order of overrides

The order of the overrides in the ini file is important, the override for a node needs to come before the override for the class that node belongs to. If it doesn't then the class template will be used, not the node template.

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?

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
    User specified parameters
    Template variables set by ezPublish
    Introduction
    Variables, arrays and objects
    Node
    Database connectivity
    Sections
    File placement
    Override templates
    node_view_gui
    Pagination
    Caching
    Stylesheets
    Pagelayout
    Printable pages
    Examples
Components
Tips & Tricks
Troubleshooting


Created

04/07/2003
11:29:45 am
by Bård Farstad

Last updated

27/10/2004
1:14:30 pm
by Frederik Holljen

Authors

Bård Farstad
Marco Stipek
Kåre Køhler Høvik
Björn Dieding@xrow.de
Frederik Holljen



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.