Optional criteria

Sometimes it’s useful to make a selection only if the environment contains the requested tag. For example, we might hope to filter the loops based on a particular search, but only if a search has been performed, otherwise display everything. In such a case, a trailing question mark is used to request such an action:

<BOUCLEx(TABLES){criterion?}>...

Example

Display either all the articles of the site (if there is no id_article, id_rubrique or recherche variable apparent), or perform a selection based on the criteria that are present. In this way, if we call the template with the id_rubrique=8 and recherche=extra parameters, the loop will select only the articles that match these criteria. This allows us to reuse the loop code in different ways within a model or with SPIP template includes.

<BOUCLE_art(ARTICLES){id_article?}{id_rubrique?}{recherche?}>
- #TITRE<br />
</BOUCLE_art>

Author Mark Baber Published : Updated : 30/05/10

Translations : English, français