set

Summary

Sets the value of a variable.

Usage

{set var1=value1 [var2=value2] [...]}

From 3.4.4 and 3.5:
{set [name=value1] scope=[global|root|relative] var1=value1 [var2=value2] [...]}

Parameters

NameTypeDescriptionRequired
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

Returns

Description

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.

Examples

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

Comments

Log in or create a user account to comment.

Contents

Reference

Database diagram
Template operators
Template functions
    GUI
    Miscellaneous
    Program flow
    Variables
       append-block
       default
       let
       sequence
       set
       set-block
Data fetching
Modules
XML tags


Created

06/02/2004
2:22:46 pm
by Balazs Halasy

Last updated

09/11/2004
2:30:44 pm
by Gunnstein Lye

Authors

Balazs Halasy
Vidar Langseid
Gunnstein Lye



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.