Documentation · ViewHelper reference

XSD schema file | vhs master

Variable / SetViewHelper

Variable: Set

Sets a single variable in the TemplateVariableContainer scope. The variable then becomes accessible as {var}.

Combines well with v:variable.get to set shorter variable names referencing dynamic variables, such as:

<v:variable.set name="myObject" value="{v:variable.get(name: 'arrayVariable.{offset}')}" />
<!-- If {index} == 4 then {myObject} is now == {arrayVariable.4} -->
{myObject.name} <!-- corresponds to {arrayVariable.4.name} -->

Note that {arrayVariable.{offset}.name} is not possible due to the way Fluid parses nodes; the above piece of code would try reading arrayVariable.{offset}.name as a variable actually called "arrayVariable.{offset}.name" rather than the correct arrayVariable[offset][name].

In many ways this ViewHelper works like f:alias with one exception: in f:alias the variable only becomes accessible in the tag content, whereas v:variable.set inserts the variable in the template and leaves it there (it "leaks" the variable).

If $name contains a dot, VHS will attempt to load the object stored under the named used as the first segment part and set the value at the remaining path. E.g. {value -> v:variable.set(name: 'object.property.subProperty')} would attempt to load {object} first, then set property.subProperty on that object/array using ObjectAccess::setPropertyPath(). If {object} is not an object or an array, the variable will not be set. Please note: Extbase does not currently support setting variables deeper than two levels, meaning a name of fx foo.bar.baz will be ignored. To set values deeper than two levels you must first extract the second-level object then set the value on that object.

Using as {value -> v:variable.set(name: 'myVar')} makes {myVar} contain {value}. /

  • Tag usage example

    <v:variable.set value="[mixed]" name="NULL">
    	<!-- tag content - may be ignored! -->
    </v:variable.set>
  • Inline usage example

    {v:variable.set(value: [mixed], name: 'NULL')}

Arguments

Argument Description Type
name

Name of variable to assign

string
value

Value to set

mixed
Required attribute

Revision history

commit da7677bc74f14e9a9300e4ba4487e52c3cb97642
Author: Claus Due <*****@namelesscoder.net>
Date:   Sun Apr 20 01:13:33 2014 +0200

    [TASK] Switch to namespaces

commit f16494865266f00f4df185236b7856aa96841039
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Sat Jun 7 22:58:04 2014 +0200

    [TASK] Replace old namespace and move v:if to v:condition and v:var to v:variable in documentaion and readme

commit 53b0c30204bc1f46f2b2c6cb13c33c49d6c39f3e
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Sun Jun 8 14:42:09 2014 +0200

    [TASK] Update vhs 2.0 namespaces
    Variable in variable PHP

commit 12ff0ddfb8d36c51f2d3befde7ae812177c80d5d
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Wed Jun 11 00:01:47 2014 +0200

    [TASK] CGL remove use leading backslash
    PHP Docs
    Note that for namespaced names (fully qualified namespace names containing namespace separator, such as Foo\Bar as opposed to global names that do not, such as FooBar),
    the leading backslash is unnecessary and not recommended, as import names must be fully qualified, and are not processed relative to the current namespace.

commit 716b251b6470782dbc09ca6e883b00cb75e5e440
Author: Claus Due <*****@namelesscoder.net>
Date:   Thu Jan 15 04:52:28 2015 +0100

    [TASK] More test ports

commit 8bb2fc5ee124ba19b0a0ab8e061c9a153fc4651f
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Sun Jan 18 17:56:13 2015 +0100

    [TASK] Reference Copyright to license.md file