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.



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:

  <BOUCLE_rubs(RUBRIQUES){racine}{0,2}{par titre}>
        <BOUCLE_arts(ARTICLES){id_rubrique}{par titre}>

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'> 
		<ul class='articles'>
			<li>Notes about this documentation</li>
			<li>Another article</li>

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

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