Custom PHP galleries with ACF Repeater subfields

Hi,
I need to create a custom gallery because the default Bricks gallery doesn’t support image metadata. I need to display the image caption and description in a lightbox. Glightbox is a great lightbox for that, but I need to have the correct markup to display metadata in the lightbox.

I use the ACF Repeater with alternating text and gallery blocks. Then, in the Bricks CPT template, I have a query which uses sections for the text and galleries. But I cannot use the standard gallery element, because it doesn’t provide metadata in the markup.

Is it possible to output the ACF gallery subfield with PHP inside a Bricks query? I mean to output the right instance of the subfield in the right place, like this:

  1. Text Block 1
  2. Gallery Block 1
  3. Text Block 2
  4. Gallery Block 2
    etc.

I tried something like this, but it doesn’t work:

<?php 
$images = get_sub_field('article_gallery');
if( $images ): ?>
    <ul>
        <?php foreach( $images as $image ): ?>
            <li>
                <a href="<?php echo esc_url($image['url']); ?>">
                     <img src="<?php echo esc_url($image['sizes']['thumbnail']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
                </a>
                <p><?php echo esc_html($image['caption']); ?></p>
                <p><?php echo esc_html($image['description']); ?></p>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

As it is inserted inside the Bricks query loop, maybe there is a way to output the correct instance of the subfield?

I know how to achieve that with single fields… But it gets messy after a certain length, so a Repeater would be preferable.

Greetings,
Tom