> $sections gelesene Abschnitte (PageSections::read) */ public function renderAll(array $sections, RenderContext $context): HtmlString { $rendered = []; $first = true; foreach ($sections as $section) { $cells = []; $units = SectionLayouts::units($section['layout']); foreach ($units as $position => $slotUnits) { $widget = $section['slots'][$position] ?? null; if (! is_array($widget)) { continue; } $html = $this->widgets->renderWidget($widget, $context, $first); if ($html !== '') { $first = false; $cells[] = ['units' => $slotUnits, 'html' => $html]; } } if ($cells !== []) { $rendered[] = ['section' => $section, 'cells' => $cells]; } } $html = ''; $last = count($rendered) - 1; foreach ($rendered as $index => $item) { $html .= $this->renderSection($item['section'], $item['cells'], $index); $divider = $item['section']['style']['divider'] ?? 'none'; if ($index < $last && in_array($divider, ['line', 'accent'], true)) { $html .= ''; } } return new HtmlString($html); } /** * @param array $section * @param list $cells */ private function renderSection(array $section, array $cells, int $index): string { $style = SectionStyle::fromStored($section['style'] ?? []); $columns = SectionLayouts::columns(array_column($cells, 'units')); $hasImage = $style['background'] === 'image' && $style['image'] !== null && PublicMedia::isPublicPath($style['image']); $classes = [ 'page-section', 'section-bg-'.($hasImage ? 'image' : ($style['background'] === 'image' ? 'default' : $style['background'])), 'section-width-'.$style['width'], 'section-space-'.$style['spacing'], ...($style['spacing_top'] !== 'same' ? ['section-space-top-'.$style['spacing_top']] : []), 'section-layout-'.str_replace('_', '-', $section['layout']), ]; if ($hasImage) { $classes[] = 'section-overlay-'.$style['overlay']; } // Bedeutungswerte der Fläche (tokens.css): helle Schrift auf dunklen Flächen, gelber Fokus. $scope = match (true) { $hasImage && $style['overlay'] === 'dark' => 'scope-dark', $hasImage => 'scope-light', $style['background'] === 'dark' => 'scope-dark', $style['background'] === 'accent' => 'scope-accent', default => null, }; if ($scope !== null) { $classes[] = $scope; } if ($style['divider'] === 'space') { $classes[] = 'section-divider-space'; } $id = is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : ''; $html = '
'; if ($hasImage) { // Das Bild des ersten Abschnitts ist meist das größte sichtbare Element und wird nicht verzögert geladen. $loading = $index === 0 ? 'loading="eager" fetchpriority="high"' : 'loading="lazy"'; $html .= ''; } $html .= '
'; foreach ($cells as $cell) { $html .= '
'.$cell['html'].'
'; } return $html.'
'; } }