SPIP

[ar] [ast] [bg] [br] [ca] [co] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [ru] [sk] [sv] [tr] [vi] [zh] Espace de traduction

Download

|alterner

July 2010 — updated on : June 2010

All the versions of this article:


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:

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

Show the template of this page Site powered by SPIP | Translation area | Private area
123