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):

  1. <Bx>
  2. Display this once, before the loop's content
  3. <BOUCLEx(TABLE){criteria}>
  4. Display something for each matching element
  5. </BOUCLEx>
  6. Display this only once, after the loop's content
  7. </Bx>
  8. Display this if there are no matching element results
  9. <//Bx>

Download

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.

  1. <B_latest_articles>
  2. <ul>
  3. <BOUCLE_latest_articles(ARTICLES){!par date}{0,5}>
  4. <li>#TITRE, <em>[(#DATE|affdate)]</em></li>
  5. </BOUCLE_latest_articles>
  6. </ul>
  7. </B_latest_articles>

Download

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:

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

Download

Author Thomas Sutton Published : Updated : 04/06/10

Translations : English, Español, français