|alterner

The |alterner{a, b, c, ...} filter is applied to a numeric tag (most often #COMPTEUR_BOUCLE) within a SPIP loop, and displays alternating argument values in rotating sequence each time the value of the tag to which it is attached change within the loop.

  • New in : SPIP 1.8.2

For example, [(#COMPTEUR_BOUCLE|alterner{white, yellow})] will display "white" the first time the the loop runs, "yellow" on the second time, "white" for the third, "yellow" for the fourth, etc.. This means we can create a list which uses different colours for the odd and even rows:

<B_lesarticles>
<ul>
<BOUCLE_lesarticles(ARTICLES) {par titre}>
<li style="background: [(#COMPTEUR_BOUCLE|alterner{white, yellow})];">#TITRE</li>
</BOUCLE_lesarticles>
</ul>
</B_lesarticles>

This filter is not binary: which means it can be used to display a data item every X times that a value changes; the following loop will diplays the article titles in blocks of 4, changing colour for each consecutive block:

<BOUCLE_lesarticles(ARTICLES) {par titre}>
[(#COMPTEUR_BOUCLE|alterner{<p style="color:red;">, '', '', '', <p style="color:green;">, '', '', ''})]
#TITRE<br>
[(#COMPTEUR_BOUCLE|alterner{'', '', '', </p>})]
</BOUCLE_lesarticles>
[(#TOTAL_BOUCLE|modulo{4}|=={0}|non)</p>]
</B_lesarticles>

Nb : Filter |alterner can be applied to other fields or calculated tags than #COMPTEUR_BOUCLE, as long as their value is a strictly positive integer.

See also

Tag

Filter

Author Mark Published : Updated : 14/07/23

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