The complete syntax of loops

Loops, like tags, have a syntax which allow them to deliver content in various combinations. Optional parts are displayed only once (not for each element) and only if the loop returns some content. An additional alternative part is displayed only if the loop does NOT return any actual content. Here is the complete syntax of a loop (x is the loop’s name):

<Bx>
    Display this once, before the loop's content
<BOUCLEx(TABLE){criteria}>
    Display something for each matching element
</BOUCLEx>
    Display this only once, after the loop's content
</Bx>
    Display this if there are no matching element results
<//Bx>

Example

This loop selects the five most recently published articles on the site. In this example, the <ul> and </ul> HTML tags will be displayed only once, and only if the loop criteria match some elements. If there are no matching elements, then these optional parts will not be output. This prevents the resulting HTML file from containing the <ul> and </ul> pair of tags without any constituent <li>...</li> child elements.

<B_latest_articles>
  <ul>
<BOUCLE_latest_articles(ARTICLES){!par date}{0,5}>
  <li>#TITRE, <em>[(#DATE|affdate)]</em></li>
</BOUCLE_latest_articles>
  </ul>
</B_latest_articles>

The #DATE tag displays the publication date of the article and the affdate filter ensures that it is in the correct language and is properly formatted.

Result:

<ul>
  <li>Content of exec file (squelette), <em>13 October 2009</em></li>
  <li>AJAX links, <em>1st October 2009</em></li>
  <li>Force language according to visitor, <em>27 September 2009</em></li>
  <li>Definition, <em>27 September 2009</em></li>
  <li>List of current pipelines, <em>27 September 2009</em></li>
</ul>

Author Thomas Sutton Published : Updated : 12/03/23

Translations : English, Español, français