Advanced Custom Fields

ACF values are available under the custom_fields property

{{ post.custom_fields.subtitle }}

Return format

Image, post, term and user are converted to entity if the return type entity is selected in the field settings

Specific fields

Flexible content

Content is parsed into an array of object, acf_fc_layout is renamed as type and remaining content is included into the data property

{% for content in post.custom_fields.flexible_content %}
  {% include content['type'] ~ '.html.twig' with { data: content.data } %}
{% endfor %}

Repeater

Content is parsed into an array

{% for content in post.custom_fields.repeater %}
  {{ content.title }} {{ content.subtitle }}<br/>
{% endfor %}

Content is parsed into an array of Image

{% for image in post.custom_fields.gallery %}
  {{ image|picture(800,600) }}
{% endfor %}

Image

Content can be converted to Image entity

{{ post.custom_fields.image|picture(800,600) }}

Post object

Content can be converted to Post entity

{% set other_post = post.custom_fields.other_post %}
<a href="{{ other_post.link }}">{{ other_post.title }}</a>

Relationship

Content can be converted to an array of Post entity

{% for other_post in post.custom_fields.relationship %}
  <a href="{{ other_post.link }}">{{ other_post.title }}</a><br/>
{% endfor %}

Last updated