Path / documentation / ez publish / technical manual / 3.8 / templates / basic template tasks

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

Basic template tasks

This section sheds light on some common issues related to template development.

Template inclusion

A template file can be included using the "include" function. Since this function makes it possible to include any file from any location within the eZ publish directory, it must be told that it should look for the file within the design directory. This can be done by prefixing the path/filename with "design:". The following example demonstrates how the include function can be used to include a template file called "footer.tpl", which is located in the templates directory of a design.

{include uri='design:footer.tpl'}

If the requested file is not found within the main design of the siteaccess, the system will search for it in the additional designs and the standard design. Please refer to the documentation of the automatic fallback system for more information about this feature.

Output washing

Variables that may contain bogus strings should always be washed using the "wash" operator. This operator makes sure that the output does not contain any elements that may mess up the HTML generated by eZ publish. The following example demonstrates how the wash operator works.

{def $bogus_string='hello < world'}

The following output will be produced:

hello < world

E-mail address obfuscation

In addition to securing proper output, the wash operator can also be used to obfuscate E-mail addresses on a web page. An obfuscated E-mail address has a less chance of getting picked up by a robot searching for E-mail addresses to put on a spammer's list. The following example demonstrates how the wash operator can be used with an E-mail address.

{def $email_address=''}
{$email_address|wash( 'email' )}

The following output will be produced:


String concatenation

The "concat" operator makes it possible to glue several strings together in order to produce a single string. The following example demonstrates how this operator works.

{def $my_string='sausage'}
{concat( 'Liver ', $my_string, ' sandwitch' )}

The following output will be produced:

Liver sausage sandwitch

Custom view parameters

The URL of a node view request may contain custom parameters. The custom view parameters must be specified at the very end of the URL using a special notation. For each parameter, a name and a value must be specified. The name must be encapsulated by paranthesis. Each element must be separated by slashes. The following example demonstrates how custom parameters can be used (in addition to the view parameters) in a system URL that requests a node.

The same parameters can be appende to the virtual URL of the node:

When custom view parameters are used, the system will create an associative array using the name of the provided parameters as the keys. All parameter values will be treated as strings. The array will be represented by the $view_parameters variable in the template. The parameters given in the examples above will produce an associative array with the following contents:










The following example demonstrates how the custom view parameters can be accessed in the template that is used to display the node.

The color is: {$view_parameters.color} <br />
The amount is: {$view_parameters.amount} <br />

The following output will be produced:

The color is: green
The amount is: 34

Balazs Halasy (03/03/2005 11:47 am)

Julia Shymova (30/04/2007 10:48 am)

Frederik Holljen, Julia Shymova


  • I'm vegetarian

    Could I suggest...

    {def $my_string='noodle'}
    {concat( 'Tempeh ', $my_string, ' stir-fry' )}

    As an alternative menu item?
  • Custom view parameters

    In some cases $view_parameters won't work, try $module_result.view_parameters there. So the example above will be:
    The color is: {$module_result.view_parameters.color} <br />
    The amount is: {$module_result.view_parameters.amount} <br />

    I hope this saves some headache..