SPIP-Contrib

SPIP-Contrib

عربي | Deutsch | English | Español | français | italiano

273 Plugins, 191 contribs On SPIP-Zone, 29 visitors now

Homepage > Templates > Tutoriaux pour squelettes > How to use an array in a template ?

How to use an array in a template ?

25 May 2008 – by Gilles Vincent, JLuc

All the versions of this article: [English] [français]

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 operations with arrays.

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>
  1. An empty table is created
  2. #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’.
  3. 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,

P.S.

L’auteur :
Gilles Vincent ( http://my.opera.com/tech-nova/blog )

Back to top

Comment on this article

Who are you?
  • [Log in]

To show your avatar with your message, register it first on gravatar.com (free et painless) and don't forget to indicate your Email addresse here.

Enter your comment here Les choses à faire avant de poser une question (Prolégomènes aux rapports de bugs. )
Add a document

Back to top

Here they're talking

  • (fr) Zpip-dist en HTML5

    15 juin 2010 – 10 <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Une surcharge des squelettes Zpip-dist qui tire parti des nouvelles balises offertes par la spécification HTML5. Attention, ce plugin n’est plus compatible avec les nouvelles versions de Zpip, qui a connu plusieurs incompatibilités de nomenclature (...)

  • (fr) Une licence pour un article

    18 avril 2007 – 25 <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Sur une idée originale de erational, voici un plugin permettant de lier une licence à un article.

  • (fr) Plugin Parrainage

    6 novembre 2011 – <blink style='color:red;'>public|spip|ecrire:commentaire</blink>

    Permettre aux utilisateurs d’inviter leurs contacts à s’inscrire sur le site. Description Vous connaissez le web moderne et son cortège d’applis toujours en version « beta » et de buzz sur le dernier réseau à la mode ? Vous voulez vous aussi vous y (...)

  • (fr) Formulaire de contact libre

    27 avril 2011 – 36 <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Dans SPIP il n’y a pas un formulaire de contact, mais autant de formulaires de contact que d’auteurs. Cette phrase de Romy, dans son article Une page de contact dans mon SPIP, pointe un petit manque de SPIP. La possibilité d’insérer rapidement un (...)

  • (fr) Plugin Mot de Passe Compliqué

    2 novembre 2007 – 16 <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Ce plugin ajoute un testeur de complexité de mot de passes dans les formulaires de choix de mot de passe de SPIP.