ez.no / ezpublish / documentation / customization / custom design / sections
These documentation pages are no longer maintained. Please visit the new documentation site.
It is often necessary to repeat elements of the template. This is very useful in lists of objects. By doing this we can define how we wish to present one object in our list, and then repeat it for each object. We do this with sections.
Example:
{section name=MySection loop=$objectList} <!-- do things here --> {/section}
This section would loop the same number of times as there is elements in $objectList. If the array $objectList is empty then this section will be ignored. Remember also to close the section with {/section}.
Each section must have a name. The name will declare the unique namespace for this section. To access a variable in the namespace you have to add the name of the namespace to the variable.
Example:
{$MySection:myvariable}
For each loop of the section we will take the next element of $objectList and place this in a variable called $item. This variable will change for each time the section loops.
Example:
{section name=MySection loop=$objectList} {$MySection:item.name}<br /> {/section}
This example will print out the name of each element in the $objectList array. We can reach the data map in the same way:
{section name=MySection loop=$objectList} <h1>{$MySection:item.data_map.title.content}</h1> {$MySection:item.data_map.intro.content.output.output_text}<br /> {/section}
A section can take another parameter called show. The parameter can be true or false and decides if the section should be shown or not. If the parameter is an array, it will be shown if the array has values and hidden if the array is empty.
{section name=NewSection show=$node.node_id|eq(2)} <!-- more stuff --> {/section}
This section will only be shown if the $node object has id 2 (eq is an equal operator and return true or false if the input and parameter are equal or not).
Example:
If we wish to print out the name of all nodes placed under the current position in the tree it could be something like this:
{let articleList=fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id, 'sort_by', $node.sort_array ) )} {section name=articleLoop loop=$articleList} {$articleLoop:item.name} {/section} {/let}
We are, as you can see, sorting the list by the sort_array variable in the node. This will ensure that it will be sorted the way that is decided by the parent node. Notice that we use a colon after the namespace. This is because articleLoop is a namespace and not an object.
Alternately we can cut down a bit on the code:
{section name=articleLoop loop=fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id, 'sort_by', $node.sort_array ) )} {$articleLoop:item.name} {/section}
Here we place the fetch function directly into the section. This will save us a few lines of code, but we don't have a name on the list, and can therefore not use it in any other way.
Comments
Use 'var' parameter instead of 'name'
James Robertson
Thursday 04 August 2005 12:47:05 am
"
It is preferred to use var instead of name. var is only supported in eZ publish 3.3 and later.
"
Dont mix up term section with section
Claus Jensen
Monday 15 September 2003 1:58:56 pm
regards,
claÜs