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.

<BOUCLEx(TABLE){criteria}>
	#ID_TABLE
	<BOUCLEy(SECOND_TABLE){id_table}>
		...
	</BOUCLEy>
</BOUCLEx>

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:

<B_rubs>
  <ul>
  <BOUCLE_rubs(RUBRIQUES){racine}{0,2}{par titre}>
    <li>#TITRE
      <B_arts>
        <ul>
        <BOUCLE_arts(ARTICLES){id_rubrique}{par titre}>
          <li>#TITRE</li>
        </BOUCLE_arts>
        </ul>
      </B_arts>
    </li>
  </BOUCLE_rubs>
  </ul>
</B_rubs>

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:

<ul class='rubriques'> 
	<li>fr
	</li>
	<li>en      
		<ul class='articles'>
			<li>Notes about this documentation</li>
			<li>Another article</li>
		</ul>
	</li>
</ul>

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

Translations : English, Español, français, Nederlands