Path

ez.no / ezpublish / documentation / customization / custom design / variables, arrays and objects


Variables, arrays and objects

These documentation pages are no longer maintained. Please visit the new documentation site.

Variables

Variables can be set with either let or default. let will always assign the value, but default will only set the variable if it is not already set, i.e. it will not override an existing variable.

Example:

{let myvalue=5}

My value: {$myvalue}

{/let}

Output:

My value: 5

Notice that both let and default should be closed with a corresponding {/let} or {/default} tag. Our variable will no longer be defined after the closing.

Attributes

Attributes are a way of accessing data in objects and arrays. The attribute is an identifier that will lookup either the index number or the key in an array or the defined attribute in an object. The access method for arrays and objects are similar which means that the template code can be fed an array or an object and the code wouldn't know the difference.

Arrays

Array elements have two types of attributes, numerical indices or identifiers.

Index lookup
{$array.1}

{$array.24}
Identifier lookup
{$array.first}

{$array.a.b.c.d.e.f}

Objects

For objects to be able to be able to handle attribute access the class must implement these following functions:

bool hasAttribute( string name )

mixed &attribute( string name )

It also recommended, but not necessary, to implement these functions.

array attributes()

setAttribute( string name, mixed value )
Example

Here's an example of how to implement attribute support.

class eZItem

{

   function attributes()

   {

       return array( "first", "second" );

   }

 

   function hasAttribute( $name )

   {

       return in_array( $name, eZItem::attributes() );

   }

 

   function &attribute( $name )

   {

       if ( $name == "first" )

           return $this->First;

       else if ( $name == "second" )

           return $this->Second;

       return null;

   }

 

   function setAttribute( $name, $value )

   {

       if ( $name == "first" )

           $this->First = $value;

       else if ( $name == "second" )

           $this->Second = $value;

   }

 

   var $First;

   var $Second;

}

Access methods

It's possible to access attributes using two different methods, this is shown below. The first uses the . operator and an identifier name or numerical index. The second uses the [ and ] brackets to enclose a new statement for which the result is used to do the lookup.

. operator
{$array.1}

{$array.first.last}
[] operator
{$array[1]}

{$array[first][last]}

It's also possible to use another variable as lookup, doing this is best suited with the [] brackets.

{$array.$index}

{$array[$iterator.key]}

Comments

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
    User specified parameters
    Template variables set by ezPublish
    Introduction
    Variables, arrays and objects
    Node
    Database connectivity
    Sections
    File placement
    Override templates
    node_view_gui
    Pagination
    Caching
    Stylesheets
    Pagelayout
    Printable pages
    Examples
Components
Tips & Tricks
Troubleshooting


Created

04/07/2003
11:26:25 am
by Bård Farstad

Last updated

08/07/2003
1:20:00 pm
by Bård Farstad

Authors

Bård Farstad



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.