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

Variable types

The eZ publish template language supports the following variable types:

  • Numbers
  • Strings
  • Booleans
  • Arrays
  • Objects

While some variable types can be created on the fly, others need to be created using an operator. Types that may be created directly are numbers and strings. Booleans and arrays must be created using operators, objects may be created using miscellaneous functions and operators. In addition to the types listed above, it is also possible to create and use custom variables. Custom variable types must be represented as objects.

Numbers

Numbers are numerical values. A number can be a positive or a negative integer or a floating point value. The following example demonstrates how different numbers can be used directly within template code:

{13}
{1986}
{3.1415}
{102.5}
{-1024}
{-273.16}

Strings

A string is an arbitrary sequence of characters (text) that is encapsulated by a matching pair of either single or double quotes, ' or ". If the quotes are omitted, the string will most likely be interpreted as a function name. Strings are usually defined in the following way:

{'This is a string.'}
{"This is another string."}

The output of the example above would be:

This is a string.
This is another a string.

Using quotes

It is possible to use quotes inside strings. This can be done by either using a different kind of quote or by making use of the escape character (backslash). The following examples demonstrate the use of quotes inside strings:

{'The following text is double quoted: "Rock and roll!"  '}
{"The following text is single quoted: 'Rock and roll!'  "}
{'Using both single and double quotes: "Rock'n roll!"   '}
{'Using both single and double quotes: 'Rock'n roll!' '}
{"Using both single and double quotes: 'Rock'n roll!'    "}
{"Using both single and double quotes: "Rock'n roll"   "}

The output of the example above will be:

The following text is double quoted: "Rock and roll!"
The following text is single quoted: 'Rock and roll!'
Using both single and double quotes: "Rock'n roll!"
Using both single and double quotes: 'Rock'n roll!'
Using both single and double quotes: 'Rock'n roll!'
Using both single and double quotes: "Rock'n roll!"

Because of the way template code is defined (encapsulated in a matching pair of curly brackets), the right curly bracket, "}", must also be prepended by the backslash escape character. The following example demonstrates this.

{'{ This text is inside curly brackets.}'}

The output of the template code above will be:

{This text is inside curly brackets.}

Template strings do not support inline expansion of variables (as in Perl and PHP). In other words, it is not possible to mix variables into strings. However, the concat operator can be used to append the contents of some variable to a string; which means that this operator can be used to build strings consisting of other strings and/or miscellaneous variables.

Booleans

Booleans are binary, they are either TRUE (1) or FALSE (0). A boolean must be created using either the "true" or the "false" template operator. Example:

{true()}
{false()}

For some operators and functions, it is possible to use integers as booleans. However, these are not "real" booleans. Zero means FALSE; all non-zero values mean TRUE. Some operators are able to treat an array as if it were a boolean value. While an empty array means FALSE, a non-empty array means TRUE.

Arrays

Arrays are containers that are capable of holding a collection of any other variable type including other arrays. An array can be a simple vector or a hash map (associative array). An element of a vector can be accessed using an index number. The number denotes the position of the element inside the array (the first element is zero, the second element is one, and so on). An element of an associative array can be accessed using both an index number and an identifier. Regular arrays can be created with the "array" operator. Associative arrays can be created with the hash operator. The following examples demonstrate the creation of arrays and hashes.

Example 1: Array of numbers

{array( 2, 4, 8, 16 )}

This example creates an array containing four numbers. The array will consist of the following elements:

Index

Value of element

 

2

1

4

2

8

3

16

Example 2: Array of strings

{array( 'This', 'is', 'a', 'test' )}

This example creates an array containing four strings. The array will consist of the following elements:

Index

Value

 

'This'

1

'is'

2

'a'

3

'test'

Example 3: Associative array

{hash( 'Red', 16, 'Green', 24, 'Blue', 32 )}

This example creates an associative array containing three key-value pairs. The array will consist of the following elements:

Index

Key

Value

 

Red

16

1

Green

24

2

Blue

32

Objects

Template objects are created by PHP code or by special template operators. An object consists of attributes where each attribute can be a different type. An attribute may represent any type of data (number, string, etc.), including another object. The contents of an attribute may be accessed by using the attribute's identifier. The system uses objects to represent complex data structures. For example, objects are used to represent information about content nodes, attributes, translations, roles, policies, etc. Please refer to the "Objects" section of the "Reference" chapter for a complete overview of the available objects and their attributes. The following illustration shows the structure (with example values) of an object ( "ezdate") that contains information about a date.

The structure of the "ezdate" object.

The structure of the "ezdate" object.

Balazs Halasy (16/02/2005 9:15 am)

Julia Shymova (19/04/2007 12:58 pm)

Balazs Halasy, Julia Shymova


Comments

There are no comments.