Translations
Info
All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

FluidSyntax

From TYPO3Wiki
Jump to: navigation, search

Fluid syntax by example

Variables

In the template's HTML code, simply wrap the variable name into curly braces to output it:

$this->view->assign('title', 'An example');
<h1>{title}</h1>

Output:

<h1>An example</h1>

Arrays and objects

Use a dot . to access array keys:

$this->view->assign(
    'data',
    array('Low', 'High')
);
<p>{data.0}, {data.1}</p>

Output:

<p>Low, High</p>

This also works for object properties:

$this->view->assign(
    'product',
    (object) array(
        'name' => 'Pear',
        'price' => 1.2
    )
);
<p>{product.name}: {product.price}</p>

Output:

<p>Pear: 1.2</p>

Accessing dynamic keys/properties

To access an object property or array key whose name is stored in a variable, put them in curly braces and v:variable.get:

$this->view->assign(
    'product',
    (object) array(
        'name' => 'Pear',
        'price' => 1.2
    )
);
$this->view->assign('labelfield', 'name');
<p><v:variable.get name="product.{labelfield}"/></p>

Output:

<p>Pear</p>

ViewHelper attributes

Simple

$this->view->assignMultiple(
    array(
        'date'   => time(),
        'format' => 'Y-m-d H:i:s'
    )
);
Now it is: <f:format.date format="{format}">{date}</f:format.date>

Objects in HTML attributes

Objects to attributes are JSON-like. Keys are not quoted, unquoted values are variables, quoted values are used as they are:

$this->view->assign('value', 23.42);
<f:format.printf arguments="{number: value}">%.3e</f:format.printf><br/>
<f:format.printf arguments="{number: 'value'}">%.3e</f:format.printf>

Output:

1.230e+2
0.000e+0