Arrays are really usefull when you have to manipulate the same
elements several times.
They have been introduced with the version 1.92 :
#ARRAY{key1,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 )"
This tag allows you to do a lot of operations with the arrays.
Example
Here is an example taken from the plugin spipbb
#SET{modos,#ARRAY}
<BOUCLE_modo_art(AUTEURS){id_article}>
#SET{modos,#GET{modos}|array_merge{#ARRAY{#COMPTEUR_BOUCLE,#ID_AUTEUR}}}
</BOUCLE_modo_art>
<BOUCLE_art_rub(ARTICLES){id_article}>
<BOUCLE_rub_admin(AUTEURS_RUBRIQUES){id_auteur !IN
#GET{modos}}{id_rubrique=#ID_RUBRIQUE}>
<BOUCLE_aut_admin(AUTEURS){id_auteur}>
#SET{modos,#GET{modos}|array_merge{#ARRAY{#COMPTEUR_BOUCLE,#_aut_admin:ID_AUTEUR}}}
</BOUCLE_aut_admin>
</BOUCLE_rub_admin>
</BOUCLE_art_rub>
- 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.
Hope it helps,
Aucune discussion
Ajouter un commentaire
Avant de faire part d’un problème sur un plugin X, merci de lire ce qui suit :
Merci d’avance pour les personnes qui vous aideront !
Par ailleurs, n’oubliez pas que les contributeurs et contributrices ont une vie en dehors de SPIP.
Suivre les commentaires : |