Skip to the content
Documentation

Template control structures

No ratings yet

Exponential 6 in this section

The control structures of the template language are the same in Exponential 6 as in 4.x. Templates can also be written in Smarty or Twig in Exponential 6; the control structures of this section are those of the native template language.

Conditional control

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

Looping

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

Deprecated

Function Summary
section Deprecated looping, branching, etc.

In this section

Contributors

Comments (4 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. substitute for {section loop=..

    patrick kaiser ·

    hi,
    you are saying here that the {section -construct should be avoided in the future. since i'm relativly new to exponential 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?

    1. Re: substitute for {section loop=..

      Alimi Nabil ·

      Hi Patrick,
      You should try the {foreach} statement.
      It works nearly the same way as the section loop.
      If you want to add conditions, then add a {if} statement.

  2. An example of using a foreach loop instead of the deprecated section?

    Charles ·

    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.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}
    </div>

    Thanks.

Comments

Add a comment

Comments are read by a moderator before they appear.