Outputting node and object data

This part of the 4.x documentation is for eZ Publish 4.0, only reference section is common for all eZ Publish 4.x versions as well as eZ Publish 5.x "LegacyStack", please select the version you are using for the most up to date documentation!

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 time-stamp, 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 time-stamp, 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:

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).

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2013 eZ Systems AS (except where otherwise noted). All rights reserved.