Skip to content

Instantly share code, notes, and snippets.

@megclaypool
Last active May 18, 2018 15:31
Show Gist options
  • Save megclaypool/cbc7f026b89e3a11c122dbcb3b06c754 to your computer and use it in GitHub Desktop.
Save megclaypool/cbc7f026b89e3a11c122dbcb3b06c754 to your computer and use it in GitHub Desktop.
Calling an External Twig File for an ACF Repeater Field How to include an external twig file for the contents of a repeater field. (WordPress, Twig, Timber, Advanced Custom Fields, ACF, Radicati)
Template:
{% if <codename-1> %}
<ul class="social-links-menu">
{% for <codename-2> in <codename-1> %}
<li>
<a href="{{<codename-2>.<repeater-subfield>}}">
{{ <codename-2>.<some-other-repeater-subfield> }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}
Example:
{% if media %}
<ul class="social-links-menu">
{% for item in media %}
<li>
<a href="{{item.awardee_social_media_link}}">
{{ item.awardee_social_media_title }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}
Template:
{% include "<path-to-external-twig-file>.twig" with
{'<codename-1>': <repeater-field>} %}
Example:
{% include "widgets/social-media.twig" with
{'media': post.get_field('awardee_social_media')} %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment