Path

ez.no / documentation / ez publish / technical manual / 5.x / 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'}
{$bogus_string|wash()}

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='allman@example.com'}
{$email_address|wash( 'email' )}

The following output will be produced:

allman[at]example[dot]com

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, ' sandwich' )}

The following output will be produced:

Liver sausage sandwich

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

http://www.example.com/content/view/full/13/(color)/green/(amount)/34

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

http://www.example.com/company/about_us/(color)/green/(amount)/34

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:

Key

Type

Value

color

string

green

amount

string

34

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

Custom view parameters in "edit.tpl" templates

In eZ Publish versions prior to 3.9, you cannot pass custom view parameters to the "edit" view of the "content" module. From 3.9, it is possible and thus you can use custom view parameters in the "edit.tpl" templates. The following example demonstrates a typical system URL in this case:

http://www.example.com/content/edit/13/03/eng-GB/(color)/green/(amount)/34

This will instruct eZ Publish to use custom view parameters, specified in the link above, when editing the "eng-GB" translation of the third version of the thirteenth content object in the system.

Balazs Halasy (14/09/2010 11:23 am)

Geir Arne Waaler (28/09/2010 11:55 am)


Comments

  • 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..
  • view_parameters inside node/view/line.tpl template

    I can't retrive view_parameters under the template node/view/line.tpl.
    • Re: view_parameters inside node/view/line.tpl template

      Try using the 'global scope' hash, like this:
      {$#view_parameters.color}