#SET and #GET

The #SET tag defines a variable that will be usable throughout the rest of the same template file.
The #GET is then used to retrieve the value of that variable.


#GET{variable} returns "value".

The variable defined by #SET may be a character string or an array.

-  A character string:
#SET{my_string, article from #NOM}

#GET{my_string} will display:
article from Jimmy

-  An array:
#SET{my_array, #ARRAY{a,one,b,two,c,three,d,four}}

[(#GET{my_array}|foreach)] will display:

  • a => one
  • b => two
  • c => three
  • d => four

Advanced uses with text strings

-  A regular expression:

#SET{reg1, '(^.*/[^/]+[/])'}
#SET{reg2, '\.[\w-_]+?'}

is designed to retrieve and display the file name of a document, enclosed by its access path and its extension.
For example, if #FICHIER is IMG/pdf/Stats_Sejour_au_311207.pdf, we would be displaying Stats_Sejour_au_311207.

A key purpose in using the #SET and #GET tags for regular expressions is that it allows the usage of brackets ([ and ]) within the |replace filter.

-  The results returned by an INCLURE:

#SET{my_return_value, #INCLURE{fond=calculations}}

Default values

If variable has not yet been defined with a #SET{variable, value} beforehand, it is possible to specify a default value when using the corresponding #GET tag:

#GET{variable, default_value}

will return "default_value" if "variable" has not been defined previously.

Warning: this method does not assign "default_value" to the "variable".

Scope of the variable defined with a par #SET

The values defined by the#SET tag remain local to the template file in which they have been defined.

In addition, the value of a variable with a SET inside an included file can not be retrieved by the corresponding GET from within the file that includes the template file with that SET.

Knowing where to place your #SET declaration

When you want a loop to provide one or more values to a variable declared with #SET you should place the declaration of this #SET before the very first opening tag of the loop.

This is particularly important when the loop is declared with its full syntax (indeed a #SET declaration placed between <B_...> and <BOUCLE_...> will be initialized after the loop execution).

See also

Les balises tableaux


Author jack, Mark Published : Updated : 28/06/23

Translations : عربي, català, English, Español, français, Nederlands