ez.no / exponential / documentation / development / libraries / ez template / basics / attributes
These documentation pages are no longer maintained. Please visit the new documentation site.
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.
Array elements have two types of attributes, numerical indices or identifiers.
{$array.1} {$array.24}
{$array.first} {$array.a.b.c.d.e.f}
It also recommended, but not necessary, to implement these functions.
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; }
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.
{$array.1} {$array.first.last}
{$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