Skip to the content
Documentation

set

No ratings yet

Summary

Sets the value of a variable.

Usage

{set $var1=value1 [ var2=value2 [...] ] [ name=name ] [ scope=scope ]}

Parameters

Name Type Description Required
var1 string Name of variable number one (with a dollar sign in front of it). Yes.
value1 any The value that should be assigned to variable 1. Yes.
var2 string Name of variable number two (with a dollar sign in front of it). No.
value2 any The value that should be assigned to variable 2. No.
name string The name of the target namespace. No.
scope string The scope ("global", "root" or "relative"). No.

Description

This function makes it possible to assign new values to variables that previously have been declared using either the "def" function. The "name" and "scope" parameters are optional and can be used to set the desired namespace and scope.

Examples

Example 1

{def $apples=4}
Before: {$apples} <br/>
...
{set $apples=8}
After: {$apples} <br/>

The following output will be produced:

Before: 4
After: 8

Example 1

{def name=ns1 $var1='ns1 org value'}
{def name=ns2 $var1='ns2 org value'}

Original values: <br/>
$ns1:var1 : {$ns1:var1} <br/>
$ns1:ns2:var1 : {$ns1:ns2:var1} <br/>
...
{set name=ns1 scope=root var1='new value'}
{set var1='new value'}
...
New values: <br />
$ns1:var1 : {$ns1:var1}<br/>
$ns1:ns2:var1 : {$ns1:ns2:var1}<br/>

The following output will be produced:

Original values:
$ns1:var1 : ns1 org value
$ns1:ns2:var1 : ns2 org value

New values:
$ns1:var1 : new value
$ns1:ns2:var1 : new value

Contributors

Comments (5 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. def using namespaces

    William Steenbergh ·

    Hi eZ Pub guys,
    In the manual for {def} it is stated that def does not support the 'name' and 'scope' parameters. In the examples of {set} however, it does. Did you simply 'search and replace' all occurences of {let} in the documentation, or do some parts of the manual need an update?

    1. Re: def using namespaces

      Alimi Nabil ·

      {set} is not {def} ;).
      Namespaces are supported by the set function but not by the def statement as mentionned in the documentation.
      In other words, you can define a variable and set a value for a specific namespace.

  2. either? what if undefined?

    zurgutt ·

    "..variables that previously have been declared using either the "def" function." - either def or what?
    And more importantly, what if variable is previously undeclared?

    1. Re: either? what if undefined?

      AtR ·

      {if is_set($module_result.node_id)}

Comments

Add a comment

Comments are read by a moderator before they appear.