Toolbox for Beaver Builder

Writing templates for fields

Mastering the Twig engine and explaining all the possibilities of Twig is beyond the scope of this documentation, but there are a few things you need to know when dealing with the output.

As any language the input needs to be valid commands. This means that starting a {% if %} {% endif %} sequence, it is imperative that the closing {% endif %} is there for the template to understand. When it's not, the script will fail and the page will crash.

Because we are designing the template on the Editor, the information that is returned is inserted using AJAX-calls. If the script fails, it will only result in that module not updating the preview. If you continue typing and complete the sequence, whenever it becomes a valid script again it will update the preview with the result.

Adding a template for a Repeater Field

Consider a repeater field with 2 subfields, 'label' and 'content'. A repeater can be zero or several iterations of this combination.

Add a ACF Field Module into the layout and select the Fieldtype and fieldname from the dropdowns.

When working with a repeater field you need to iterate over the items inside the __field__ variable. An easy way is to do this is by using the for .. endfor loop. Item is a mere variablename and can be used to query each subitem.

So, inside the for...endfor loop we can get the label and content fields by using

{{item.label}} and {{item.content}}

resulting in the following layout:

toolbox_docs-acf-field-repe2
toolbox_docs-acf-field-repe1
Last modified: October 30th, 2018