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

|foreach

August 2010

All the versions of this article:

The |foreach filter applies the squelettes-dist/modeles/foreach.html model to display the key=>value pairs of the table to which it is applied in a legible fashion.


-  After #SET{tablo, #ARRAY{0,a,1,b,2,c,3,d}},
[(#GET{tablo}|foreach)] will return:

  • 0=> a
  • 1=> b
  • 2=> c
  • 3=> d

-  If &tab[]=aa&tab[]=bb&tab[]=cc&tab[]=dd is passed in the URL of a page,
[(#ENV{tab}|foreach)] will return :

  • 0=> aa
  • 1=> bb
  • 2=> cc
  • 3=> dd

-  If the tag to which the |foreach filter is applied is a serialised table array (refer to the PHP functions at), then it is essential to apply the |unserialize filter to it after having asterisked it just beforehand:
for example: [(#ENV*|unserialize|foreach)].

-  You can force the use of another model apart from foreach.html by calling the filter with an argument: [(#GET{tablo}|foreach{my_model})] where my_model.html is the customised model to use and which has been stored in the squelettes/modeles/ directory.

-  Example: display the list of the names of the active plugins used on the site

The modeles/plugin_list.html mode file would contain:
  [<li>(#ENV{valeur}|strtolower)</li>]
and would therefore be called with:
  [<ul>(#PLUGIN*|unserialize|foreach{plugin_list})</ul>]


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