megclaypool of Rootid
4/23/2018 - 7:29 PM

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')} %}