Nested loops

It is often useful to nest loops within each other to display more complicated elements. Nesting loops in this way makes it possible to use values from the first, outer, loop as selection criteria for the second, inner, loop.

  1. <BOUCLEx(TABLE){criteria}>
  2. #ID_TABLE
  3. <BOUCLEy(SECOND_TABLE){id_table}>
  4. ...
  5. </BOUCLEy>
  6. </BOUCLEx>

Download

Example

Here we list all of the articles contained in the first two sections of the site. We use the {racine} criteria to select only the top-level sections, which are usually call "sectors" in SPIP:

  1. <B_rubs>
  2. <ul>
  3. <BOUCLE_rubs(RUBRIQUES){racine}{0,2}{par titre}>
  4. <li>#TITRE
  5. <B_arts>
  6. <ul>
  7. <BOUCLE_arts(ARTICLES){id_rubrique}{par titre}>
  8. <li>#TITRE</li>
  9. </BOUCLE_arts>
  10. </ul>
  11. </B_arts>
  12. </li>
  13. </BOUCLE_rubs>
  14. </ul>
  15. </B_rubs>

Download

The ARTICLES loop uses a sorting key {par titre} (“by title”) and a criterion {id_rubrique}. This last criterion instructs SPIP to select articles that belong to the current section — in this case, the one that is currently selected by the RUBRIQUES loop.

This will output:

  1. <ul class='rubriques'>
  2. <li>fr
  3. </li>
  4. <li>en
  5. <ul class='articles'>
  6. <li>Notes about this documentation</li>
  7. <li>Another article</li>
  8. </ul>
  9. </li>
  10. </ul>

Download

Author Thomas Sutton Published : Updated : 23/05/10

Translations : English, Español, français