0
votes

I have an ACF repeater field which repeats out images using Timber in wordpress. My code is as...

{% for item in item.get_field('product_images')}} 
{{TimberImage(item.product_image).src('thumbnail')}}
{% endfor %}

Pretty simple and this returns all the rows I have added to this repeater as expected, but I only want to return the first row, i.e. the first image in the repeater.

I see you can simply break out of the loop using the ACF syntax but just can't figure out it its possible to do using Timber. Any ideas would be great. Thanks.

1
pluck( array $array, string $key ) maybe? so - pluck( item.get_field('product_images'), '0' ) should return your first row in your repeater? - Stender
Hi, thanks but not sure how to actually implement this. Could you provide an example? Cheers. - mfos

1 Answers

1
votes

Ok, slightly different approach. Upon reading twig docs further I came across loop-variables

So we can do this...

{% for item in item.get_field('product_images') %}
   {% if loop.first %}
      <img src="{{TimberImage(item.product_image).src('thumbnail')}}" alt="{{item.product_title}}">
   {% endif %}  
{% endfor %}

And check only for the first row and display it. Easy-peasy.