|foreach

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.

  • New in : SPIP 2.0
  • Deprecated since : SPIP 4.0

-  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>]

Author Mark Published : Updated : 28/07/23

Translations : català, English, français, Nederlands