Solved it now with a quick’n’dirty solution.
I’m simply iterating over my while loop in the controller and in the content-page.blade.php template.
controller:
function acf_data( $data ) {
if( have_rows('inhaltselemente') ):
$row = 0;
while ( have_rows('inhaltselemente') ) : the_row();
if( get_row_layout() == 'title_and_content' ):
$data['title_text_background_color'][$row] = get_sub_field('background_color');
elseif( get_row_layout() == 'download' ):
$data['download'] = get_sub_field('file');
endif;
$row++;
endwhile;
endif;
return $data;
}
add_filter( 'sage/template/page/data', 'App\\acf_data' );
content-page.blade.php
@if(have_rows('inhaltselemente'))
<?php $row = 0; ?>
@while (have_rows('inhaltselemente')) @php(the_row())
@if (get_row_layout() == 'title_and_content')
@include('partials/content-element-title-and-text')
@elseif (get_row_layout() == 'dividing_line')
@include('partials/content-element-dividing-line')
@endif
<?php $row++; ?>
@endwhile
@else
// no layouts found
@endif
That way I can call the correct value:
{{ $title_text_background_color[$row] }}