• News
  • Developer information
  • Projects & contributions
  • Forum
  • Issue tracker
  • Open Funding
  • Security
  • User groups
  • Support
  • Store
  • Company

  • Path

    ez.no / exponential / documentation / development / libraries / ez template / basics / attributes


    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.

    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

    • 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

    Development

    Extensions
    Exponential datamodel
    Exponential tuning and stability
    Importing attribute data
    Kernel
    Libraries
        eZ xml
        eZ db
        eZ i18n
        eZ soap
        eZ template
           Basics
              Functions
              Operators
              Attributes
              Comments
              Namespaces
           Functions
           Operators
        eZ webdav
    Scripting
    Standards
    System overview
    Test Suite
    Using Doxygen to create API documenta...


    Created

    07/07/2003
    3:25:55 pm
    by Bård Farstad

    Last updated

    07/07/2003
    3:25:55 pm
    by Bård Farstad

    Authors

    Bård Farstad



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