Reputation: 71
I have this loop written so I can easily make a 'page builder' with Advanced Custom Fields. Recently I switched to Blade, but I can't get this loop to work properly. This loop works but I cant use any blade tags in my includes. If I use php to echo fields rather than {{ the_field('field'); }} it works. But I want to use {{ the_field('field'); }} in my include. If I use the tag now, it echoes the tag itself.
Can someone point me in the right direction?
@php
$flexible_content = '';
if( have_rows('partials', get_queried_object_id()) ):
while( have_rows('partials', get_queried_object_id()) ): the_row();
$row_layouts = [
'content-1',
];
foreach( $row_layouts as &$layout ) {
if( get_row_layout() == $layout ):
ob_start();
include( get_template_directory() . '/views/partials/'.$layout.'.blade.php' );
$flexible_content .= ob_get_clean();
endif;
}
endwhile;
endif;
echo $flexible_content;
@endphp
Thanks!
Upvotes: 0
Views: 192
Reputation: 190
It's normal that your code is not working,
Inside a blade @php tag, the blade syntax is desactivated, so you have to use the php syntax.
Blade syntax is just an other way to use php, when you use {{ $something }}
blade read it and translate it to <?php echo $something ?>
for the server.
It is the same for the if
and the while
instruction, you have to use {}
instead of endif
and endwhile
.
Upvotes: 0