{si ...}

The {si ...} criterion is used to condition the execution of a loop to the condition expressed as an argument in the criterion.

  • New in : SPIP 3.0

Example :

<BOUCLE_art(ARTICLES) {si #ID_RUBRIQUE|=={8}} {par date}>
  <a href="#URL_ARTICLE">#TITRE</a>
</BOUCLE_art>

The loop will be executed only if, in the execution environment of the loop, #ID_RUBRIQUE is equal to "8".

The conditional part of the loop, the one written between </B_art> and <//B_art>, will be executed in the two cases where :

  • either #ID_RUBRIQUE does not exist in the environment or is not equal to 8 (taking into account the criterion {si ...} ;
  • or #ID_RUBRIQUE is indeed equal to 8 but the loop does not return any result.

This new criterion {si ...}, available from SPIP 3.0, allows to at last get rid of the impossibility to use a loop in the conditional part of a tag.
For example, where it was necessary to write

  [(#SESSION{statut}|=={1comite}|oui) <INCLURE{fond=mypage, ...}> ... ]

because mypage.html contained a loop, it is now possible to write directly into the calling template (without INCLURE):

  <BOUCLE_xy(AUTEURS) {si #SESSION{statut}|=={1comite}}> ...

Of course, the criterion {si ...} can be related to any type of variables (#ENV, #GET,...)
For example, a loop whose execution will be conditioned by the result of a calculation involving a variable from the environment #ENV{var} (retrieved from the url) and a variable #GET{val} (previously defined in the template):

#SET{val, 2}
<BOUCLE_a(ARTICLES) {si #ENV{var}|plus{#GET{val}}|=={5}}>
...

See also

The CONDITION loop

Author jack Published : Updated : 23/07/23

Translations : English, français, Nederlands