.. include:: /Includes.rst.txt :navigation-title: Expressions .. _expressions-syntax: ========================= Fluid Syntax: Expressions ========================= The syntax for expressions in Fluid is a mix between plain variable access (e. g. `{variable}`) and ViewHelper usage in inline mode (e.g. `{myArray -> f:count()}`). Fluid's expression syntax is extendable, but in most circumstances the following features are available. See :ref:`Expression Nodes ` to learn how to extend Fluid's expression behavior. .. _objects-syntax: Objects and arrays ================== Within a ViewHelper call, arrays (with numeric keys) and object structures can be defined inline: .. code-block:: xml These can also be nested and indented: .. code-block:: xml Trailing commas are valid syntax and are recommended to create cleaner diffs in version control systems. .. _type-casting: Type casting ============ The `as` expression can be used to convert variables to a different type. `{myPossiblyArray as array}` will for example make sure you access `{myPossiblyArray}` as an array even if it is of another type :php:`null`, which is useful when you pass a suspect value to a ViewHelper like `f:for` which requires an array as input. Other supported cast types are: `integer`, `boolean`, `string`, `float` and `DateTime`. If you use `as array` on a string that contains comma-separated values, the string is split at each comma, similar to PHP's `explode `__ function. .. _math-expressions: Math expressions ================ Fluid supports basic math operations. For `myNumber = 6`, the following expressions result in: .. code-block:: xml {myNumber + 3} {myNumber - 3} {myNumber * 3} {myNumber / 3} {myNumber % 3} {myNumber ^ 3} .. _ternary-expressions: Ternary Expressions =================== Fluid supports the ternary operator for variables. It is a shortcut to switch between two variables based on the value of a variable. For static values, like a string, this is **not** supported. .. code-block:: xml {checkVariable ? thenVariable : elseVariable} If `{checkVariable}` evaluates to :php:`true`, variable `{thenVariable}` will be used, otherwise `{elseVariable}` will be used.