Path / documentation / ez publish / technical manual / 3.7 / reference / template control structures

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

Template control structures

Conditional control

if Allows conditional control by the way of an IF-THEN-ELSE mechanism.
switch Allows conditional control of code execution.


do Creates a do...while loop.
for Creates a generic for loop.
foreach Iterates over arrays in different ways.
while Creates a while loop.


section Deprecated looping, branching, etc.

Balazs Halasy (22/02/2005 12:59 pm)

Balazs Halasy (07/07/2005 11:44 am)


  • Section?

    Where's the {section} command?

    This is one of the most-used template control structures. Why isn't it here?
    • Re: Section?


      because in 3.6 they decided to do away with old template syntax in favor of a newer one which is more unified with common programming languages.

      3.6 is back-compatible though, so you'll be able to use the syntax you're used to, and run your old code under it (shipped templates with 3.6 ARE using the old syntax, yet). but for new development tasks, I think you'll be better offusing the newer syntax.
  • substitute for {section loop=..

    you are saying here that the {section -construct should be avoided in the future. since i'm relativly new to ez-publish i'd like to get used to the the 'right' ways of template programming right from the beginning. but i cannot find a way to loop over results from a fetch differently than the old {section loop=... way.

    i tried it with {while and {for statments with no success..

    what is best practice for looping over results using the new control structures?
  • An example of using a foreach loop instead of the deprecated section?

    Hi. Could someone provide an example of how to use a foreach loop instead of the deprecated section loop. Let's say I have the following code and want to use a foreach loop instead of a section:
    <div class="listItem">
    {default node_name=$ node_url=$node.url_alias}
    {foreach (
    {section show=$node_url}<a href={$node_url|ezurl}>{/section}{$node_name|wash}{section show=$node_url}</a>{/section}{/default}