{si ...}

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

Example :

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

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

  1.   [(#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):

  1.   <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


Author jack Published :

Translations : English, français, Nederlands