list_item()

Twig function of the framework; its result is HTML and is printed without escaping.

{{ list_item(path) }}

Marks the root element of an item of a list with appender (#[ListOf(appender: true)]). In renders for the block editor the list has one more item, empty, as long as it is below its max; the editor shows that item faded and adds it on a click. Write it directly after the tag name, without a space, like field(). The output is HTML: an attribute in renders for the block editor, otherwise '', at once and without looking at the path. In the editor the path must name an item of a list with appender of the rendered block; otherwise an exception is thrown.

{% for button in attrs.buttons %}
    <a{{ list_item(['buttons', loop.index0]) }} href="{{ button.url }}"{{ field(['buttons', loop.index0, 'label']) }}>{{ button.label }}</a>
{% endfor %}
ParameterTypeDefaultDescription
pathlist<string|int>requiredThe names to the list and the index of the item, e.g. ['buttons', 2].

Returns string