Toolbox Twig filters

Estimated reading: 2 minutes

fl_builder

You can use this Twig filter to display something only while user is logged in and the editor is active.

Parameters

  • none

Usage

{% set fields = toolbox_get_fields(['name','address','city']) %}
{{toolbox_dump(fields)|fl_builder}}

of_type()

You can use this Twig filter to display something only while user is logged in and the editor is active.

Parameters

  • type (string) (optional) type to test for; options are: ‘array’, ‘bool’, ‘class’, ‘float’, ‘int’, ‘numeric’, ‘object’, ‘scalar’, ‘string’, null
  • classname (string) (optional) when testing for type ‘class’ an aditional classname must be provided

Usage

{% set fields = [ 'name', 345, { id: 789 } ] %}
<p>first field is of type: {{ fields[0]|of_type }}</p>
<p>second field is of type: {{ fields[1]|of_type }}</p>
<p>third field is of type: {{ fields[2]|of_type }}</p>

will output:

<p>first field is of type: string</p>
<p>second field is of type: integer</p>
<p>third field is of type: array</p>

cast_to_array

When your filters return an object to your Twig template, you might need to change it to an array to be able to work with it. You can use this filter to do that easily.

Parameters

  • none

Usage

{% set __field__ = __field__|cast_to_array %}
Share this Doc

Toolbox Twig filters

Or copy link

CONTENTS