Sage 10 v 10.1.7 Problem with composers

Hi, i use composers with acf flexible content builder first time and i have some problems.

My file structure:

// layouts.app.php
<main id="main" class="main" style="padding-bottom: 2000px">
    @yield('content')
</main>
// front-page.app.php
@extends('layouts.app')
@section('content')
    @while(have_posts()) @php(the_post())
    @include('partials.page-header')
    @includeFirst(['partials.content-page', 'partials.content'])
    @endwhile
@endsection
// content-page.app.php
@foreach ($builder as $section)
    @php $name = $section['acf_fc_layout']; @endphp
        @include('builder.builder-' . $name, ['block' => $section])
@endforeach

$builder is a variable from composer, in $builder i have a array or fields (acf fiexible).

<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;

class PageBuilder extends Composer
{
    protected static $views = [
        'partials.content-page',
    ];

    public function with()
    {
        return [
            'builder' => get_field('fields')
        ];
    }
}

and finally i include file with builder component. Every components use layouts.section

// Component

{{ 'BEFORE LAYOUTS SECTION' }}
@dump($block)

@extends('layouts.section')


@section('section-content')
    {{ 'INSIDE SECTION CONTENT' }}
    @dump($block)
    <div class="container">
        <div class="wysiwyg">

        </div>
    </div>
@endsection
 // layouts.section

<div class="test">
    @yield('section-content')
</div>

I added important comments in component file. I add two the same components in admin panel (the same acf flexible components) and dump data.


BEFORE LAYOUTS SECTION
^ array:7 [▼
  "acf_fc_layout" => "wysiwyg"
  "section-theme" => "element-paper-theme"
  "vertical-spacing" => array:4 [▶]
  "wysiwyg-columns" => "1"
  "wysiwyg" => """
    <p>Curabitur nisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus nec sem in justo pellentesque facilis ▶
    <p>Praesent turpis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat e ▶
    <p>Sed lectus. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Suspendisse potenti. Ut tincidunt tincidunt erat. Donec pede justo, fringilla ve ▶
    <p>Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna. Phasellus viverra nulla ut metus varius laoreet. Ut leo. Ut tincidunt tincidunt erat. ▶
    """
  "wysiwyg1" => ""
  "wysiwyg2" => ""
]
INSIDE SECTION CONTENT
^ array:7 [▼ ▼
  "acf_fc_layout" => "wysiwyg"
  "section-theme" => "element-paper-theme"
  "vertical-spacing" => array:4 [▶ ▶]
  "wysiwyg-columns" => "1"
  "wysiwyg" => """
    <p>Curabitur nisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus nec sem in justo pellentesque facilis ▶
    <p>Praesent turpis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat e ▶
    <p>Sed lectus. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Suspendisse potenti. Ut tincidunt tincidunt erat. Donec pede justo, fringilla ve ▶
    <p>Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna. Phasellus viverra nulla ut metus varius laoreet. Ut leo. Ut tincidunt tincidunt erat. ▶
    """
  "wysiwyg1" => ""
  "wysiwyg2" => ""
]
BEFORE LAYOUTS SECTION
^ array:7 [▼
  "acf_fc_layout" => "wysiwyg"
  "section-theme" => "element-dark-theme"
  "vertical-spacing" => array:4 [▶]
  "wysiwyg-columns" => "2"
  "wysiwyg" => ""
  "wysiwyg1" => "<p>Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Nam commodo suscipit quam. Praesent porttitor, nulla vitae posuere iaculis, ar ▶"
  "wysiwyg2" => """
    <p>Cras ultricies mi eu turpis hendrerit fringilla. Fusce neque.</p>
    <p><img loading="lazy" class="alignnone size-medium wp-image-43" src="https://bibabo.lndo.site/wp-content/uploads/2022/06/half_hero-300x167.webp" alt="" width=" ▶
    """
]
INSIDE SECTION CONTENT
^ array:7 [
  "acf_fc_layout" => "wysiwyg"
  "section-theme" => "element-paper-theme"
  "vertical-spacing" => array:4 []
  "wysiwyg-columns" => "1"
  "wysiwyg" => """
    <p>Curabitur nisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus nec sem in justo pellentesque facilisis. Quisque ut nisi. Phasellus ullamcorper ipsum rutrum nunc.</p>
    <p>Praesent turpis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Fusce neque.</p>
    <p>Sed lectus. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Suspendisse potenti. Ut tincidunt tincidunt erat. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p>
    <p>Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna. Phasellus viverra nulla ut metus varius laoreet. Ut leo. Ut tincidunt tincidunt erat. Fusce neque.</p>
    """
  "wysiwyg1" => ""
  "wysiwyg2" => ""
]

Why in last dump i have a value from previous field?
whether I am sending the data correctly? Is impossible to use composer with reusable fields?
I tested this also with many composer configuration, but always i have the same issue.

Hey Grzesiek,

Could you try return your fields in your function first? as below:

    public function with()
    {
        return [
            'builder' => $this->builder(),
        ];
    }

   // Return the field
  public function builder() {

    return get_field('fields');
  
  }

With this, you should have access in your partial view to $builder variable with array of your fields

Unfortunately it does not work. The variable loses the assigned value when calling the block @section('section-name) @endsection

Architecture of my app looks like this:

1.front-page.blade.php (use layout app) -> include page-content.php (get builder fields, its work correct) -> include block (based on name in builder array, block use layout section)

Maybe i cant use layout in layout?

I don’t know the exact reason why you’re seeing this behavior, but when debugging odd Blade problems it often helps to look at the “cached” files generated from your blades, since they contain actual PHP and will show you how exactly things are being accomplished.

My guess is that layouts are not really intended to be used like this, and using them in a loop causes the problem you’re seeing. I’d recommend taking a look at the Blade docs: Blade Templates - Laravel - The PHP Framework For Web Artisans Based on that, you might consider using a Component for this section, rather than a layout. My understanding is that “layouts” are intended to be high-level “wrappers” rather than chunks of replicable content.