@php
// Page::$casts declares content as `array`, so landing-page
// rows return a PHP array of structured sections instead
// of a plain HTML string. We detect that here and surface
// it in the UI: show a blue banner explaining what's on
// screen, and offer a "Flatten to HTML" action that the
// user can opt into if they want to edit as plain text.
$rawContent = $page->content;
$isStructured = is_array($rawContent);
$contentForEditor = $isStructured
? json_encode($rawContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
: (string) ($rawContent ?? '');
// Build an HTML preview from the array structure so the
// "Flatten to HTML" button has something sensible to drop
// into the textarea. Walks known section shapes: title,
// subtitle, desc, reasons[], items[], features[], etc.
$flattenHtml = '';
if ($isStructured) {
$walk = function ($node) use (&$walk) {
if (is_string($node)) {
return '
' . e($node) . '
' . "\n";
}
if (! is_array($node)) {
return '';
}
$out = '';
if (! empty($node['title'])) {
$out .= '
' . e($node['title']) . '
' . "\n";
}
if (! empty($node['subtitle'])) {
$out .= '
' . e($node['subtitle']) . '
' . "\n";
}
foreach (['desc', 'description', 'body', 'text', 'content'] as $k) {
if (! empty($node[$k]) && is_string($node[$k])) {
$out .= '
' . e($node[$k]) . '
' . "\n";
}
}
foreach (['reasons', 'items', 'features', 'sections', 'cards'] as $listKey) {
if (! empty($node[$listKey]) && is_array($node[$listKey])) {
$out .= "\n";
foreach ($node[$listKey] as $item) {
$out .= $walk($item);
}
}
}
return $out;
};
$flattenHtml = trim($walk($rawContent));
}
@endphp
@if($isStructured)
{{ __('This page uses structured sections') }}
{{ __('The content below is stored as JSON so your landing page can render it in sections (hero, reasons, features, etc.). Edit the JSON keys/values to change individual sections, or convert to plain HTML if you prefer a simple rich-text page.') }}
@endif
@error('content')
{{ $message }}
@enderror