Hi all,
I'm writing a tag that needs to pass an array of options into a template
and then loop over the values in it (generation <option> tags). When
I've needed to do this in the past, I serialize()d the array in the tag,
and then embedded PHP in the template to unserialize() and then loop
over this value.
Is there a better way to achieve this (without having to add new types
of SPIP loops or defining another template that conditionally includes
itself)?
What are the version of your SPIP ? 2.0 ?
The plugin "SPIP-Bonux" lets you play with array looping thanks to the POUR (for) loop.
<BOUCLE_my_loop(POUR){tableau #ENV{my_array}}>
#CLE (key)
#VALEUR (value)
</BOUCLE_my_loop>
It is the most very mega super ultimate simple solution.
More and more plugins create a dependency with Bonux ( <necessite id="spip_bonux" version="[1.2;]" /> ) just for this feature.
The same plugin offers you a condition loop in order to do others loops *inside* the condition: because you can't loop inside conditional tags like [(#TAG|condition|oui) a conditional thing without loops].
<BOUCLE_test(CONDITION){si #TAG|condition|blabla}>
if true
<BOUCLE_yeah(ARTICLES)>
wow so cool, I can make loops here
</BOUCLE_yeah>
</BOUCLE_test>
if false
<//B_test>
On another note, for the SPIP developers:
I have been working on a plug-in with tags that call other tags (like
#INCLUDE/#INCLURE and #ENV/#GET/#CONFIG) and dynamic tags that build
global data-structures during template compilation and then use them
during the code generation phase. Whoever designed this part of the
system is very clever indeed! SPIP has (in my opinion) a number of rough
spots, but this is certainly not one of them! It's a please to work with.
If you please playing with dynamic tags, and if you are using SPIP 2, have you heard of the new layer CVT = Charger-Vérifier-Traiter = Load-Verify-Process. It's a method less esoteric than the "balise_" one, but it's in fact a layer *over* the former method. So you can also use a combination.
There is an explanation in french here:
and here:
Shortly : the mecanism CVT is a functional cutting of the function balise_THING_dyn($params).
But you can always use balise_THING_stat() if you have to recuparate variables from the environment.
Exemple:
and:
I hope this helps you...