.. _fluid-viewhelpers-quick:
=====================
Fluid ViewHelpers
=====================
T3Toon registers the Fluid namespace **toon** so you can encode, decode, and estimate tokens directly in Fluid templates. Add the namespace and use the ViewHelpers as shown below.
Namespace
---------
In your Fluid template, add:
.. code-block:: html
xmlns:toon="http://typo3.org/ns/RRP/T3Toon/ViewHelpers"
Or ensure the namespace is available (registered in ext_localconf as ``toon``).
toon:encode
-----------
Encodes a value to TOON format.
**Arguments:**
* **value** (required) — Data to encode (array, object, scalar)
* **options** (optional) — Preset: ``default``, ``compact``, ``readable``, ``tabular``; default: ``default``
**Examples:**
.. code-block:: html
toon:decode
-----------
Decodes a TOON string to a PHP array. You can assign the result to a variable and use it in child content (e.g. ``f:for``), or output JSON.
**Arguments:**
* **toon** (required) — TOON-formatted string to decode
* **as** (optional) — Variable name to assign the decoded array to; if set, child content is rendered and the variable is available inside
* **lenient** (optional) — If ``true``, do not coerce scalar types; default: ``false``
**Examples:**
.. code-block:: html
{item.name}
...
toon:estimateTokens
-------------------
Estimates token count for a TOON string. Outputs ``tokens_estimate`` by default, or assigns the full stats array to a variable.
**Arguments:**
* **toon** (required) — TOON string to estimate
* **as** (optional) — Variable name to assign the result (keys: ``words``, ``chars``, ``tokens_estimate``); if set, child content is rendered
**Examples:**
.. code-block:: html
Words: {stats.words}, Chars: {stats.chars}, Tokens: {stats.tokens_estimate}
Full template example
----------------------
.. code-block:: html
…
{stats.tokens_estimate}