The |alterner{a, b, c, ...} filter (since SPIP 1.8.2) 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.

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>})]

Author Mark Published : Updated : 26/10/12

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