Search code examples
wordpressadvanced-custom-fieldstimber

ACF Gallery Field


I am trying to use this plugin in my first Timber project but I have issues displaying the gallery. I have created the custom field named "gallery" and tried with the below code but I can't get the gallery to work.

`<div>
        {% for image in post.get_field('gallery') %}
            <img src="{{ Image(image) }}" />
        {% endfor %}
</div>`

I have also tried:

{% for image in post.meta('gallery') %}
   <img src="{{ Image(image) }}" />
{% endfor %}

Solution

  • The ACF Photo Gallery Field plugin will give you a PHP array of images, instead of the image ID normally returned by the ACF image gallery field.

    One way to check what data is returned is to print the output using {{ dump(post.meta('gallery') }} with WP_DEBUG enabled, and then using this a reference to construct your gallery.

    Update: If a comma delimited string is being returned, you can try split it into indiviual ID's to loop

    {% for image in post.meta('gallery')|split(',') %}
       <img src="{{ Image(image) }}" />
    {% endfor %}