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:

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

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;">, '', '', ''})]
[(#COMPTEUR_BOUCLE|alterner{'', '', '', </p>})]

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



Author Mark Published : Updated : 14/07/23

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