set
Sets shared, session or runtime variables by passing key/value pairs as option array.
<@ set { variable: 'value' } @>
Shared Variables
Variables defined by this function are shared and can be accessed in any context. Note that therefore it is not possible to override page variables using this function. Note that in case you don't want defined variables to show up in the dashboard it is therefore also possible to define runtime variables instead.
<# Define variables. #>
<@ set {
variable: 'Some text ...',
another: 'More here ...'
} @>
<# Use variables. #>
@{ variable }
@{ another }
Session Variables
In case a variable needs to be saved across multiple requests, it can be stored in the internal session data array. Session variable names always start with a %
.
<# Define a variable in the session data array. #>
<@ set { %variable: 'Some text ...' } @>
<# Use a session data variable. #>
@{ %variable }
Runtime Variables
To hide defined variables from the dashboard which are only used during runtime and therefore shoudn't be modified by users, it is possible to use the runtime variable syntax as follows:
<# Define a runtime variable. #>
<@ set { :variable: 'Some text ...' } @>
<# Use that variable. #>
@{ :variable }
Example
The following example is taken from the session template of the theme skeleton package and demonstrates how to store a query string parameter in a session variable.
<@ if @{ ?lang } @>
<@ set { %lang: @{ ?lang | 5 } } @>
<@ end @>