# Best Practice / Resources for Blade

**URL:** https://discourse.roots.io/t/best-practice-resources-for-blade/8341
**Category:** sage
**Tags:** sage9, blade
**Created:** 2016-12-16T20:07:36Z
**Posts:** 180
**Showing post:** 51 of 180

## Post 51 by @vdrnn — 2017-02-14T10:49:47Z

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] }}`

---

_[View the full topic](https://discourse.roots.io/t/best-practice-resources-for-blade/8341)._
