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:
- 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)
Ricardo Correia (17/04/2013 1:21 pm)
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
Friday 16 February 2007 12:32:11 pm
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: Re: For an speed boost and lowering number of fetches / sql quries
Friday 27 October 2006 1:38:45 pm
André
.children and some other variables are dynamicly feched if you use them.
So it's better to use tree fetch if you want content on different levels!
attributes can be pre-fetched or computed upon request
Friday 16 February 2007 12:46:40 pm
Svitlana Shatokhina
http://ez.no/doc/ez_publish/techn...ence/objects/ezcontentobjecttreenode (see the "static" column in the table of attributes)
For explanation, read the "Attribute availability" section located here:
http://ez.no/doc/ez_publish/techn...e_language/variable_types#attributes
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
Friday 16 February 2007 12:03:44 pm
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
Friday 16 February 2007 12:51:30 pm
vytis
is it correct?
$node.data_map.my_selection.class_content.options[$node.data_map.my_selection.data_text].name
Working example
Monday 02 October 2006 3:15:00 am
Mike LECOMTE
{for 0 to $node.object.data_map.options02.content|count()|dec as $counter}
<li> ID : {$node.object.data_map.options02.content[$counter]} - VALUE : {$node.object.data_map.options02.class_content.options[$node.object.data_map.options02.value[$counter]].name}</li>
{/for}
</ul>
dynamically accessing data_map
Wednesday 15 November 2006 5:24:06 pm
zurgutt
Relations
Friday 16 February 2007 11:52:36 am
P. Renaud
- output data only if attribute has some content :
- if my_attribute is an object relation :
- if my_attribute is an object relation list :
Language ID
Wednesday 02 April 2008 4:15:30 am
Andry
Thanks
Re: Language ID
Wednesday 02 April 2008 9:09:43 am
Svitlana Shatokhina
Thank you!