You can pass one or more parameters to code segments that have been included in a template. By default, nothing is passed to included code except the processing date. To pass parameters to the compilation context of the template, they must be explicitly declared when calling the include:
<INCLURE{fond=include_template}{parameter} />
<INCLURE{fond=include_template}{parameter=value} />
The first example with
{parameter}
only retrieves the value of
#PARAMETER
and passes it to the compilation context in the variable
parameter
. The second example assigns a specific value to that
parameter
variable. In both cases, within the included code, we can retrieve the value by reference using
#ENV{parameter}
.
{{{Passing the entire current context}}}
The
{env}
parameter can be used to pass the entire template compilation context to the code that is being included.
Example
// file A.html
<INCLURE{fond=B}{type}{key=# newt} />
// file B.html
<INCLURE{fond=C}{env}{colour=red} />
// file C.html
Type : #ENV{type} <br />
Keyword : #ENV{key} <br />
Colour : #ENV{colour}
If we call the page
spip.php?page=A&type=animal
, that would pass the
type
and
key
parameters to the
B.html
template segment. This third example passes everything it has received and adds another parameter
colour
when it calls the
C.html
template segment.
Within the
C.html
template, we then see that it is possible to retrieve all of the parameters that have been passed.