ez.no / exponential / documentation / reference / template functions / variables / set
{set var1=value1 [var2=value2] [...]}
From 3.4.4 and 3.5:
{set [name=value1] scope=[global|root|relative] var1=value1 [var2=value2] [...]}
| Name | Type | Description | Required |
|---|---|---|---|
| name | string | Name of namespace (from 3.4.4 and 3.5) | no |
| scope | Scope of name (from 3.4.4 and 3.5) | no | |
| var1 | mixed | Name of variable to set | yes |
Assigns a value to one or more variables. The value must have been created earlier using let or default.
From 3.4.4 and 3.5 you can set the namespace and scope for variables. (The current namespace is the default.) In earlier versions you can only set variables in the current namespace.
example
In this example we initialize a variable named var with 'let'. We then assign a new value to var with 'set'
{let var=4} Before: {$var}<br/> {set var=42} After: {$var}<br/> {/let}
example
This example, which is valid for versions older than 3.4.4 and 3.5, shows that you may only change variables in the current namespace. Once you are in namespace ns2, you cannot alter variables in ns1. (For the new namespace support, see the next example.)
{let name=ns1 var1='ns1 org value'} {let name=ns2 var1='ns2 org value'} original values:<br/> $ns1:var1 : {$ns1:var1}<br/> $ns1:ns2:var1 : {$ns1:ns2:var1}<br/> reassign value in namespace ns2<br/> {set var1='new value'} $ns1:var1 : {$ns1:var1}<br/> $ns1:ns2:var1 : {$ns1:ns2:var1}<br/> {/let} {/let}
The output of this example is
original values: $ns1:var1 : ns1 org value $ns1:ns2:var1 : ns2 org value reassign values in namespace ns2 $ns1:var1 : ns1 org value $ns1:ns2:var1 : new value
example
This example, which is valid for versions newer than or equal to 3.4.4 and 3.5, shows how you can change variables in various namespaces. (For the old functionality, see the previous example.)
{let name=ns1 var1='ns1 org value'} {let name=ns2 var1='ns2 org value'} original values:<br/> $ns1:var1 : {$ns1:var1}<br/> $ns1:ns2:var1 : {$ns1:ns2:var1}<br/> reassign value in namespace ns1<br/> {set name=ns1 scope=root var1='new value'} reassign value in namespace ns2<br/>{* (the current namespace is the default) *} {set var1='new value'} $ns1:var1 : {$ns1:var1}<br/> $ns1:ns2:var1 : {$ns1:ns2:var1}<br/> {/let} {/let}
The output of this example is
original values: $ns1:var1 : ns1 org value $ns1:ns2:var1 : ns2 org value reassign values in namespace ns1 reassign values in namespace ns2 $ns1:var1 : new value $ns1:ns2:var1 : new value
Log in or create a user account to comment.
Comments