Fluid Syntax: Variables 

Accessing variables 

Variables in Fluid can be accessed with the following braces {} syntax:

<h1>{title}</h1>
Copied!

Arrays and objects 

Use the dot character . to access array keys:

<p>{data.0}, {data.1}</p>
Copied!

This also works for object properties:

<p>{product.name}: {product.price}</p>
Copied!

These object properties are obtained by evaluating a fallback chain, which includes various getter methods as well as direct property access. For example, the following PHP-equivalents would be checked for {product.name}:

$product->getName()
$product->isName()
$product->hasName()
$product->name
Copied!

Also, both ArrayAccess and the PSR ContainerInterface are supported.

Dynamic keys/properties 

It is possible to access array or object values by a dynamic index:

{myArray.{myIndex}}
Copied!

Reserved variable names 

The following variable names are reserved and must not be used:

  • _all
  • true
  • false
  • null

New in version Fluid 5.0

Starting with Fluid 5, all variable names starting with an underscore are reserved for internal purposes as well. Note that this only affects the primary variable name, not the name of array keys or object properties.

<!-- invalid variable access -->
{_temp}
{_somethingElse}

<!-- valid variable access -->
{data._something}
{myArray._myKey}
Copied!