ExpressionEngine / Coilpack

ExpressionEngine + Laravel: a powerful combination
https://expressionengine.github.io/coilpack-docs/
MIT License
21 stars 3 forks source link

Preview of Fluid field strange results #12

Closed acutedeveloper closed 3 months ago

acutedeveloper commented 4 months ago

I have been using the Fluid field and the field groups inside blade templates.

What I have noted is in the entry preview, it appears to not output the content in the same way as a frontend template.

This is my fluid field with a field group

Screenshot 2024-07-10 at 16 46 57

This is my template index.html.blade

@forelse($exp->channel->entries(['channel' => 'pages']) as $entry)
    <h1>{{ $entry->title }}</h1>
    <div>
        @foreach($entry->fluid_content_body as $row)
            @if($row->_field_name == 'hero_section')
                <div style="background: #0CAFEB; padding: 1rem; margin-bottom: 1rem;">
                @foreach($row->fields as $field)
                    @if($field->_field_name == 'pf_heading')
                        <h2>{{ $field }}</h2>
                    @elseif($field->_field_name == 'pf_intro_text')
                        <div>{!! $field !!}</div>
                    @endif
                @endforeach
                </div>
            @elseif($row->_field_name == 'feature_sections')
                @foreach($row->fields as $field)
                    @if($field->_field_name == 'pf_heading')
                        <h2>{{ $field }}</h2>
                    @elseif($field->_field_name == 'pf_intro_text')
                        <div>{!! $field !!}</div>
                    @endif
                @endforeach
            @endif
        @endforeach
    </div>
    @empty
    <span>No blog entries</span>
@endforelse

On the frontend, the Hero section it renders like this:

Screenshot 2024-07-10 at 16 49 17

In the entry preview the hero section renders like this:

Screenshot 2024-07-10 at 16 50 58

I had thought that there was something wrong with my markup, but when I inspect the page I can see EE is looping my whole div, 1 per field.

I was able to confirm this by adding @php dd($row->fields) @endphp

@forelse($exp->channel->entries(['channel' => 'pages']) as $entry)
    <h1>{{ $entry->title }}</h1>
    <div>
        @foreach($entry->fluid_content_body as $row)
            @if($row->_field_name == 'hero_section')
                @php dd($row->fields) @endphp // Added dd() here
                <div style="background: #0CAFEB; padding: 1rem; margin-bottom: 1rem;">
                @foreach($row->fields as $field)
//.....

In my frontend template I get:

Illuminate\Support\Collection {#2468 ▼ // ee/system/user/templates/default_site/layouts.group/index.html.blade
  #items: array:4 [▼
    "pf_heading" => Expressionengine\Coilpack\Models\FieldContent {#2404 ▶}
    "pf_intro_text" => Expressionengine\Coilpack\Models\FieldContent {#2399 ▶}
    "component_selector" => Expressionengine\Coilpack\Models\FieldContent {#2401 ▶}
    "pf_main_image" => Expressionengine\Coilpack\Models\FieldContent {#2414 ▶}
  ]
  #escapeWhenCastingToString: false
}

In the entry preview the output is:

Illuminate\Support\Collection {#2468 ▼ // ee/system/user/templates/default_site/layouts.group/index.html.blade
  #items: array:1 [▼
    "pf_heading" => Expressionengine\Coilpack\Models\FieldContent {#2404 ▶}
  ]
  #escapeWhenCastingToString: false
}

The expected result is for the output be the same. Hopefully this explains enough. Please let me know if you need more clarification.

bryannielsen commented 3 months ago

This turns out to be an issue in ExpressionEngine that will be fixed in version 7.5.0

I'll close this issue since it is not related to Coilpack.