Skip to the content
Documentation

Variable types

No ratings yet

Template values are numbers, strings, booleans, arrays and objects. Numbers and strings are written directly; booleans and arrays are made with operators; objects come from the system: from the variables a view sets, from fetch functions and from the attributes of other objects.

Numbers

Whole numbers and decimals, positive or negative:

{13}
{-273.16}
{$price|mul( 1.25 )}

Strings

A string is text between single or double quotes; both work the same. A quote of the other kind can be used inside, and a quote of the same kind is escaped with a backslash:

{'He said "hello"'}
{"It's here"}
{'It\'s here'}

Strings do not expand variables: 'Hello $name' prints the dollar sign and the name as they are. Join values with concat instead: {concat( 'Hello ', $name|wash )}.

Booleans

The operators true() and false() make the two boolean values. Printed, true() gives 1 and false() gives nothing. Conditions also accept other values: zero, an empty string and an empty array count as false, everything else as true.

{def $show_dates = true()}
{if $show_dates}...{/if}

Arrays

array() makes a list, indexed from 0; hash() makes an associative array from pairs of key and value:

{def $sizes = array( 2, 4, 8, 16 )
     $colors = hash( 'red', 16, 'green', 24, 'blue', 32 )}
{$sizes.1}          {* 4 *}
{$colors.green}     {* 24 *}
{$sizes|count}      {* 4 *}
{undef $sizes $colors}

An array cannot be changed in place; operators such as append, array_merge and remove return a new array, which you store with {set}. How elements are read is described in Variable usage.

Objects

Objects represent the system's data: a content node (eZContentObjectTreeNode), its object (eZContentObject), an attribute (eZContentObjectAttribute), a user, a section, an order. Their attributes are read with a dot, like the keys of an associative array: $node.name, $node.​object.​published, $node.​data_​map.​title.​content. Templates read objects; they cannot change them.

Some attributes are computed only when you read them, and may cost database queries, for example $node.children or $node.​object.​reverse_​related_​contentobject_​array. Read such an attribute once into a variable instead of in every pass of a loop. Every attribute of a node and of an object is listed in the template language manual: node attributes, object attributes. To see what an object holds while you write a template, use attribute and dump.

More on values and literals: Values and literals.

In this section

Contributors

Comments (2 historical)

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

  1. Array access syntax

    Alex Farran ·

    This does not tell me how to access an element in an array/hash. What is the equivalent syntax for $my_array[1], $my_array[1][2], $my_array['key']
    My guess is $my_array.1, $my_array.1.2, $my_array.key

    1. Re: Array access syntax

      Alex Farran ·

      Turns out the answer is in the next chapter.

Comments

Add a comment

Comments are read by a moderator before they appear.