I have this foreach loop in a template
<!-- resources/views/partials/content-single-in-depth.blade.php -->
@if( $flexible_content['content'] )
@foreach( $flexible_content['content'] as $content )
@switch( $content['content_type'] )
@case( 'title-block' )
@include('partials.flex-title-block', $content)
@break
@case( 'full-width-image' )
@include('partials.flex-full-width-image', $content)
@break
@endswitch
@endforeach
@endif
The Full Width template looks like this:
<!-- resources/views/partials/flex-full-width-image.blade.php -->
<div class="{{ $component_class }}">
<div class="row no-gutters">
<div class="col-sm-12">
<figure>
{{$image}}
</figure>
</div>
</div>
</div>
Finally, the Composer class:
// app/View/Composers/FlexFullWidthImage.php
<?php
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
class FlexFullWidthImage extends Composer
{
public function with($data, $view)
{
return [
'image' => image($data),
'component_class' => classes($data),
];
}
function image($data)
{
return wp_get_attachment_image( $data['image'], $data['fw_image_size'], false, $data['image_classes'] );
}
function classes($data)
{
$classes = array_merge( ['fluid-container', 'westex-vr-full-width'], $data['narrow_class'] );
return implode( ', ', $classes );
}
}
When calling the content-single-in-depth.blade.php
and getting to that include I get an error Undefined variable: component_class
. Which I’m assuming means that the Composer file isn’t being called. IS this how I should be doing this in a loop? I have increasingly more complicated ACF flexible layouts to render, so if not what would be the best way to pass an array of values to template? I know of Components but unless I’ve misunderstood them everything needs to be a string that gets passed to them.