Path

ezpublish / documentation / ez publish / technical manual / 3.7 / templates / information extraction / outputting node and object...


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.

Outputting node and object data

Once an "ezcontentobjecttreenode" object representing a node is available in a template variable, it can be used to output information about the node and the contents of the object that the node encapsulates. The following text demonstrates the extraction of the most common elements.

General information

The name of the object

{$node.name|wash}

The name of the object is directly available through the node (in other words it is possible to reach it by $node.name instead of $node.object.name). The "wash" operator is used for making sure that the output doesn't contain any bogus characters and/or sequences that may mess up the HTML.

The date/time when the object was first published

{$node.object.published|l10n( 'shortdatetime' )}

Since the publishing value is stored as a UNIX timestamp, it must be properly formatted for output. This can be done by using the "l10n" operator, which makes it possible to format different types of values according to the current locale settings.

The date/time when the object was last modified

{$node.object.modified|l10n( 'shortdatetime' )}

Since the modification value is stored as a UNIX timestamp, it must be properly formatted for output. This can be done by using the "l10n" operator, which makes it possible to format different types of values according to the current locale settings.

The name of the user who initially created the object

{$node.object.owner.name|wash}

The name of the user who last modified the object

{$node.object.current.creator.name|wash()}

The name of the class which the object is an instance of

{$node.object.class_name|wash()}

Object attributes

The attributes of the object can be reached by the way of the "data_map" method. This method returns an associative array of "ezcontentobjectattribute" objects where each object represents one of the attributes. The keys of the array are the class attribute identifiers. The following example demonstrates how an attribute called "first_name" can be reached using the object's data map.

{$node.object.data_map.first_name}

The example above will not produce any valuable output because the requested data needs to be formatted. There are two ways of outputting the contents of attributes:

  • Raw output (the ".output" extension)
  • Formatted output (the "attribute_view_gui" function)

The main difference between raw and formatted output is that formatted output makes use of a template which in turn outputs the requested data. Raw output simply outputs the data within the same template where the request for output was issued. Output should always be presented through the "attribute_view_gui" function. The raw output method should only be used when/if necessary (for example when checking the value of an attribute using an IF statement).

Raw output

Raw output is exactly what the definition indicates: a raw dump of the contents that are stored by the attribute. The actual syntax depends on the datatype that represents the attribute. In most cases, it is possible to generate the output by appending ".output" to the identifier.

Generic solution

The following example demonstrates how to output the contents of an attribute called "my_attribute".

{$node.object.data_map.my_attribute.content}

XML block

The following example demonstrates how to output the contents of an XML block called "my_xml".

{$node.object.data_map.my_xml.content.output.output_text}

Image

The following example demonstrates how to output an image stored by an attribute called "my_image".

<img src="{$node.object.data_map.my_image.content[image_size].full_path}" ... />

Formatted output

Each datatype has a set of templates which are used to display the contents in different contexts. There are at least two templates for each datatype: a view template and an edit template. While the view template is used to display information, the edit template is used when the data is being edited. The default templates for the datatypes are located within the standard design: "/design/standard/templates/content/datatype".

The "attribute_view_gui" function makes it possible to display the contents of an attribute by inserting the view template of the datatype that the attribute uses. The following example demonstrates how this function can be used.

{attribute_view_gui attribute=$node.object.data_map.name_of_any_attribute}

The example above will generate proper output for any attribute (regardless of the datatype).

Balazs Halasy (16/02/2005 10:41 am)

Balazs Halasy (06/06/2005 11:10 am)


Comments

  • node display

    to display the values of the node variable:
    {$node|attribute(show,2)}
    
  • For an speed boost and lowering number of fetches / sql quries

    If you need to display some information about the children or grand children in the node template this is possible with $node.children and $node.children.0.children (if any children exist this will loop thru any children of your first child)
    To loop thru children:

    <table>
    {foreach $node.children as $nodechild}
       <tr>
        <td><a href={$nodechild.url_alias|ezurl}>{$nodechild.name}</a></td>
        <td>{$nodechild.node_id}</td>
      </tr>
    {/foreach}
    </table>
    


    The same thing can be done with parents: $node.parent

    Remember to only use $node in node templates and not in your pagelayout file.
    Because it&#8217;s not available on cached pages (ViewCaching).
    • Re: For an speed boost and lowering number of fetches / sql quries

      correction:
      {foreach $node.children as $nodechild}
        {$nodechild.url_alias|ezurl}
        {$nodechild.name}
        {$nodechild.node_id}
      {/foreach}