⇒ http://my.opera.com/tech-nova/blog/
Un site qui recense les astuces et évolutions des possibilités de SPIP.
Howto use an array in a template ?
Mars 2008, Par tech-novaArrays are really usefull when you have to manipulate the same elements several times.
A new tag has been introduced with the version 1.92 :
#ARRAYkey1,value1,key2,value2… allows the creation of a variable length table (useful for constructing a table for a #SET and/or for use with a dynamic « IN » criterion )
Short but an exemple should be helpfull..
Here is an exemple extracted from the plugin SpipBB
#SET{modos,#ARRAY}
#SET{
modos,
#GET{modos}
|array_merge{#ARRAY{#COMPTEUR_BOUCLE,#ID_AUTEUR}}
}
#SET{
modos,
#GET{modos}
|array_merge{#ARRAY{#COMPTEUR_BOUCLE,#_aut_admin:ID_AUTEUR}}
}
- An empty table is created
- #ARRAY#COMPTEUR_BOUCLE,#ID_AUTEUR creates an array containing the author’s id at an index that isn’t used yet.
The standard PHP function array_merge() finally does it’s job : this value is now stored on the last index of the array ’modos’. - Another loop completes this array with the other authors of articles that are in the same section.
Note that the PHP function is used as a filter : it’s possible because it’s first argument is the array to manipulate.
Of course all this can be done with PHP code inside the template. The advantage of using the tag #ARRAY is that your template is better managed by the cache.
→ Lire la suite sur le site d’origine…
