ibexa

Path

ez publish / technical manual / 3.8 / templates / information extraction / outputting node and object...


Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

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:

    &lt;table>
    {foreach $node.children as $nodechild}
       &lt;tr>
        &lt;td>&lt;a href={$nodechild.url_alias|ezurl}>{$nodechild.name}&lt;/a>&lt;/td>
        &lt;td>{$nodechild.node_id}&lt;/td>
      &lt;/tr>
    {/foreach}
    &lt;/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's not available on cached pages (ViewCaching).
    • Re: Re: For an speed boost and lowering number of fetches / sql quries

      This is wrong!

      .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!
  • Show

    What is show? A function?
    I don't see it documented anywhere but I can see its being used in many templates.

  • raw output of an image attribute

    Under some circumstances, in my case HostMatchType = URL and non-virtual host mode, the following syntax
    &lt;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):

    &lt;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

    there is missing example, how to display value of Selection object

    is it correct?
    $node.data_map.my_selection.class_content.options[$node.data_map.my_selection.data_text].name
  • Working example

    <ul>
    {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

    Apparently you can do this, to dynamically access attributes:
                {foreach $attribute_names as $attname}
                    {$node.object.data_map.[$attname].content}
                {/foreach}
     
    
  • Relations

    You could find these informations elsewhere, but here are some useful things :

    - output data only if attribute has some content :
    {if $node.data_map.my_attribute.has_content}
        {* do whatever must be done *}
    {/if}
    


    - if my_attribute is an object relation :
    {def $my_relation_object=$node.data_map.my_attribute.content.main_node}
    {* display $my_relation_object *}
    


    - if my_attribute is an object relation list :
    {def $my_relation_list_object=$node.data_map.my_attribute.content.relation_list}
    {foreach $my_relation_list_object as $current_object}
        {* display $current_node *}
    {/foreach}
    
  • regarding template for pdf file

    Hello I want pdf template for invoices file