0

I have checked the documentation and various posts and could not find examples of this. What I want is to access a field of a group, which is within a repeater in ACF Pro, using Timber/Twig.

What I have is:

{% for item in post.meta('main_field') %}

{{ item.normal_field }} // outputs fine

{% for group_name in item.main_field %}
{{ group_name.group_field }} // outputs nothing
{% endfor %}

{% for group_name in item %}
{{ group_name.group_field }} // outputs only the first instance
{% endfor %}

{% endfor %}

If I put {{ item.group_name.group_field }} I get only the data from the first item output.

I have also tried adding {% set group = post.meta('group_name') %} both before and after {% for item in post.meta('main_field') %} which outputs nothing, when referenced by {{ group.group_field }}.

So how do you reference a group within a repeater?

Yan White
  • 19
  • 7
  • What does `{{ dump( post.meta('main_field') }}` give you? – Gchtr Jul 26 '20 at 14:07
  • Good shout. I had to add a closing comma to the dump statement. This then threw an error initially: Fatal error: Uncaught Twig\Error\SyntaxError: Unknown "dump" function I had to add ``` add_filter( 'timber/twig', function( \Twig\Environment $twig ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG && class_exists( 'Ajgl\Twig\Extension\BreakpointExtension' ) ) { $twig->addExtension( new Ajgl\Twig\Extension\BreakpointExtension() ); } return $twig; } ); ``` – Yan White Jul 26 '20 at 17:30
  • to functions.php as dump is disabled by default. Getting the dump output pointed me towards a classic user error. The content of my fields was cleared when moving them inside a group field. Amazing how I failed to actually check the content! ``` {% for group_name in item %} {{ group_name.group_field }} {% endfor %} ``` works as expected. Many thanks – Yan White Jul 26 '20 at 17:30
  • Oop, yeah, sorry, I missed that ")"! I’m glad you got it working! – Gchtr Jul 27 '20 at 13:50

0 Answers0