field()

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

{{ field(path) }}

Marks the element that shows an inline field (#[PlainText], #[RichText] or #[Image]), so the block editor edits it in the canvas. Write it directly after the tag name, without a space; for an image field put it on an element around the image, such as a figure. The output is HTML: an attribute in renders for the block editor, otherwise ''. Outside of renders for the block editor it returns '' at once, without looking at the path, so it costs nothing on the front end. In the editor the path must name an inline field of the rendered block that is edited in the canvas (not with inspector: true); otherwise an exception is thrown.

<h1{{ field('headline') }}>{{ attrs.headline }}</h1>
<figcaption{{ field('caption.text') }}>{{ attrs.caption.text }}</figcaption>
{% for button in attrs.buttons %}
    <a href="{{ button.url }}"{{ field(['buttons', loop.index0, 'label']) }}>{{ button.label }}</a>
{% endfor %}
ParameterTypeDefaultDescription
pathstring|list<string|int>requiredName of the field, a dotted path into a value class (caption.text), or a list of names and list indexes for fields of list items.

Returns string