Skip to the content
Documentation

Node templates

No ratings yet

A node template shows one content node. Exponential uses one whenever it displays a node: when a visitor opens the node's address (its URL alias, such as /company/about-us), when the system address /​content/​view/​full/​<node id> is requested, and when a template shows a node with node_view_gui.

View modes

A node is shown in a view mode. The address of a node always uses full; the system address names the mode (/​content/​view/​line/​42), and a template names it in node_view_gui. The template of a view mode is node/​view/​<mode>.​tpl. The standard design of 6.0.15 has these:

full, line, listitem, embed, embed-inline, text, text_linked, thumb, plain, print, pdf, execute_pdf, search, sitemap, toolline, objectrelationlist.

A design can add view modes of its own by adding templates. A list of a folder's children typically shows each child in the line view:

{foreach $node.children as $child}
    {node_view_gui content_node=$child view='line'}
{/foreach}

node_view_gui renders node/view/line.tpl for each child, and the override rules for that template apply, so each class can have its own line view. See node_view_gui.

The $node variable

Every node template, whatever the view mode and whether it is an override or not, receives the node as $node: an eZContentObjectTreeNode with the node's attributes and, through $node.object and $node.data_map, its object and the object's content. How to print them is described in Outputting node and object data. A full view template also receives $view_parameters (see Basic template tasks).

A template per class

A site rarely shows every node alike: an article needs another layout than a folder or the front page. Such templates are override templates: they are placed in override/templates/ of a design and chosen by rules in override.ini, for example "use full/article.tpl for node/view/full.tpl when the class is article":

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

The rules, their conditions and their order are described in The template override system; the Template Editor in the administration interface writes such rules for you (The Template Editor).

Where the templates are

A design that only changes the look of nodes usually needs a templates/​pagelayout.​tpl and a few files in override/templates/; everything else comes from the designs after it in the design chain, ending with the standard design. For a design called example:

design/example/templates/pagelayout.tpl
design/example/override/templates/full/article.tpl
design/example/override/templates/full/folder.tpl
design/example/override/templates/line/article.tpl

Never edit design/standard/: it is replaced on every upgrade. Put your files in your own design, preferably in an extension (see Designs and design order).

Contributors

Comments (2 historical)

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

  1. Template variables in node templates

    André R. ·

    $node
    $viewmode
    $language_code
    $view_parameters
    $collection_attributes
    $validation
    $persistent_variable ( false )
    $node_path

  2. Illustrations

    Finn Mathisen ·

    The illustrations are not shown

Comments

Add a comment

Comments are read by a moderator before they appear.