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
Friday 11 November 2005 9:54:37 am
heiner
{$node|attribute(show,2)}
For an speed boost and lowering number of fetches / sql quries
Thursday 12 January 2006 9:54:53 am
AtR
To loop thru children:
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’s not available on cached pages (ViewCaching).
Re: For an speed boost and lowering number of fetches / sql quries
Thursday 12 January 2006 10:23:13 am
AtR
Show
Friday 03 February 2006 3:51:54 pm
Neeraj
I don't see it documented anywhere but I can see its being used in many templates.
raw output of an image attribute
Tuesday 07 March 2006 9:21:59 am
Bergfrid Skaara
<img src="{$node.object.data_map.my_image.content[image_size].full_path}" ... />
does not provide a sufficient path and the image will consequently not be displayed.
In that case do the following steps:
1) check the value of the src parameter in the source code of your page
2) compare that value to the one you get by using attribute_view_gui to show my_image
3) if the difference is that the latter starts with the name of the folder eZ publish is installed in, then you should include the ezroot operator like this (note the removal of quote marks):
<img src={$node.object.data_map.my_image.content[image_size].full_path|ezroot} ... />
ps: this issue is reported in bug report no. 7917
missing example how to display value of Selection object
Wednesday 08 March 2006 3:46:55 pm
vytis
is it correct?
$node.data_map.my_selection.class_content.options[$node.data_map.my_selection.data_text].name