Preview of Fluid field strange results
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.
- EE v7.4.11
- Coilpack v1.3.2
This is my fluid field with a field group
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:
In the entry preview the hero section renders like this:
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.