Blade and ACF flexible content best practice

I’ve put standalone variables for ACF in a Controller but can’t figure out the best practice for more complex variables with ACF such as the flexible content fields. For example, if I have a simple Flexible content type of “FlexibleContent” that includes 2 conditional rows, “Row1, Row2” with a subfield of “text”, here is how I would script it using PHP.

if( have_rows('FlexibleContent') ):
    while ( have_rows('FlexibleContent') ) : the_row();

        if( get_row_layout() == 'Row1' ):

        elseif( get_row_layout() == 'Row2' ):


However, using Blade with the Controllers, I’m not sure the best practice to put the logic. Do I just include the PHP? If I try to translate it to Blade with something like the following, I get a parse error. Still struggling to understand how the controller fits into the Blade view and how to pass complex data in. Also, what would be the best practice to declare the get_row_layout() == 'Row1' from the controller? If you have any links/resources, I’d love to read them and thanks in advanced!


public function flexiblecontent()
    return (object) array(
        'layout' => have_rows('FlexibleContent'),
        'subfield' => the_sub_field('TextBox'),
        'subfield2' => the_sub_field('TextBox2'),

Blade View

@if( {{$flexiblecontent->layout}} ):
    @while( {{$flexiblecontent->layout}} ) @php( the_row() )

    @if ( get_row_layout() == 'Row1' ) @php

    @elseif( get_row_layout() == 'download' ):


1 Like