Skip to content

Blocks and ACF Fields

By default fields assigned to the block are available through the context.

You access your block's fields in the index.twig file by using the fields variable. The example below shows how to display a block's field. We'll use "heading" as the example ACF field slug, but it could be whatever slug you give your field in the ACF UI or in the .json file for the ACF group that is assigned to the block.

{{ fields.heading }}

Here's an example of how to loop through a repeater field where "features" is the ACF field name and the repeater field has a heading field.

{% for feature in fields.features %}
    {{ feature.heading }}
{% endfor %}

ACF Fields and the Block Class

Inside the block class (BlockName.php), the field is available like so:

$this->fields['example_field'];

Or you can use the getter method:

$this->get_field('example_field');