Skip to the content
Documentation

Template override example

No ratings yet

This example gives a small site four templates of its own: one for the front page, one for folders, one for articles and one for products. The site has a front page (node 2) with two folders below it, News with articles and Products with products, and uses a design called example for the siteaccess eng.

The rules

In settings/​siteaccess/​eng/​override.​ini.​append.​php:

<?php /* #?ini charset="utf-8"?

# The front page: node 2
[full_front_page]
Source=node/view/full.tpl
MatchFile=full/front_page.tpl
Subdir=templates
Priority=10
Match[node]=2

# Folders
[full_folder]
Source=node/view/full.tpl
MatchFile=full/folder.tpl
Subdir=templates
Priority=20
Match[class_identifier]=folder

# Articles
[full_article]
Source=node/view/full.tpl
MatchFile=full/article.tpl
Subdir=templates
Priority=30
Match[class_identifier]=article

# Products
[full_product]
Source=node/view/full.tpl
MatchFile=full/product.tpl
Subdir=templates
Priority=40
Match[class_identifier]=product

*/ ?>

The front page is a folder too, so its rule must be tried before the folder rule: it has the lowest Priority. Without Priority values the rules are tried in the order of the file, which gives the same result here; the numbers make the order explicit and leave room between them for later rules.

The templates

design/example/templates/pagelayout.tpl
design/example/override/templates/full/front_page.tpl
design/example/override/templates/full/folder.tpl
design/example/override/templates/full/article.tpl
design/example/override/templates/full/product.tpl

A first full/folder.tpl that lists the folder's children, each in its line view:

<h1>{$node.name|wash}</h1>
{attribute_view_gui attribute=$node.data_map.short_description}
{def $children = fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id,
                                                 'sort_by', $node.sort_array,
                                                 'limit', 20 ) )}
{foreach $children as $child}
    {node_view_gui content_node=$child view='line'}
{/foreach}
{undef $children}

The attribute identifiers (here short_description) depend on your classes; {$node.​data_​map|attribute( 'show', 1 )} lists them (see Array and object inspection).

What is used where

Page Template
The front page (node 2) full/front_page.tpl
News, Products and every other folder full/folder.tpl
An article full/article.tpl
A product full/product.tpl
A node of any other class node/view/full.tpl from the first design that has it

Clear the caches after adding the rules and templates (see The template override system), then check the result with template path comments, which name the template and the rule's Source for each part of the page (see Debugging templates). The same rules can be made without editing a file, in the Template Editor.

In this section

Contributors

Comments (9 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. overrides don't work :(

    Mateusz ·

    Hi,
    I do everything as specified but my overrides still don't work!!
    Is it matter of file/folder permissions or what, beczuase I cannot figure it out?
    Pls help [email protected]
    THANKS:)

    1. Re: overrides don't work :(

      Olav Bringedal ·

      tried clearing the caches (especially .ini caches?
      This is the first thing to do when you don't get the result you expected. Exponential's caching system is very complex and sometimes you need to clear the entire cache to see a change.

  2. How I got overrides to work

    Viktor ·

    First, it may work better if you don't name your override exactly as the original.
    This is what I did:
    Create a design extension, and put all templates in the override directory.
    I did not have to make up new names then.
    I always put all overrides in the override-directory, it seems to have higher priority.
    Also make sure that the override.ini is loaded (check in ini-settings for your siteaccess through the admin interface)

    1. Re: How I got overrides to work

      Viktor ·

      Note, it's a little bit trickier to override an extensions design (ie ezwebin)
      That's where my problem originated..

      1. Re: Re: How I got overrides to work

        Emix ·

        How do you do that? I've got a problem

  3. Confused

    aweenk ·

    its doesn't work.. sorry i'm a newbie in Ez enggine...

  4. gone images

    Salieras ·

    Would be much better to see images, thanks.

  5. override priority

    fernando ·

    it seems that in case of conflict override (like the example of the home template) the system choose the one that come first in the override.ini. It is better that you place your custom override at the top of that configuration file.
    I think this is a kind of bug, it should be based on a well defined system of priority like that the 'node' condition has higher priority of the 'class' condition.

Comments

Add a comment

Comments are read by a moderator before they appear.