SPIP

[ar] [bg] [ca] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [sv] [tr] [vi] [zh] Espace de traduction

Download the latest version of SPIP

SPIP 1.9.2 SPIP 1.9.2

Loops within loops

Displaying content from several levels

October 2003

All the versions of this article:


We know how to generate a list of titles in a section. Now we are going to display on the same page the section’s own elements: its title, its explanatory text, etc.

Let’s try.

Here’s a solution:

You call the page with the URL http://yoursite.net/tutorial.php3?id_rubrique=1. So, what’s happening here?

Our ARTICLES loop is integrated in a RUBRIQUES (section) loop. The ARTICLES loop’s context is the id_rubrique given by the RUBRIQUES loop, which will itself have the context given by the URL (id_rubrique=1). Therefore we are at the ARTICLES level, within the requested id_rubrique. At this point nothing has changed.

However, the RUBRIQUES loop allows SPIP to select the field values for the section in question: one can thus display the section’s #TITRE and #TEXTE. Note that this instance of #TEXTE would be that of the section even if we were also to call the article’s #TEXTE within the ARTICLES loop. The display function of SPIP guarantees that #TEXTE of an article does not interfere with identically named tags in the outer loop.

Finally, a filter has been introduced |justifier on the #TEXTE field. This filter justifies the contents of the text before inserting it in the final page.


ٍShow the template of this page Site created with SPIP | Translation area | Private area