diff --git a/config/default.php b/config/default.php index 5ce28776e..e5e57b786 100644 --- a/config/default.php +++ b/config/default.php @@ -202,6 +202,9 @@ 'dir' => 'components', // components directory 'ext' => 'twig', // components files extension ], + //'sections' => [ // override layout name of sections (optional) + // '
' => '', + //] ], 'themes' => [ 'dir' => 'themes', // where themes are stored diff --git a/src/Config.php b/src/Config.php index edaa88287..cfd86ebb7 100644 --- a/src/Config.php +++ b/src/Config.php @@ -238,6 +238,18 @@ public function getLayoutsInternalPath(): string return Util::joinPath(__DIR__, '..', (string) $this->get('layouts.internal.dir')); } + /** + * Returns the layout for a section. + */ + public function getLayoutSection(?string $section): ?string + { + if ($layout = $this->get('layouts.sections')[$section] ?? null) { + return $layout; + } + + return $section; + } + /** * Returns the path of translations directory. */ diff --git a/src/Renderer/Layout.php b/src/Renderer/Layout.php index c3c38f6ee..fe274e0ec 100644 --- a/src/Renderer/Layout.php +++ b/src/Renderer/Layout.php @@ -82,6 +82,8 @@ protected static function lookup(CollectionPage $page, string $format, \Cecil\Co // remove potential redundant extension $layout = str_replace(".$ext", '', (string) $page->getVariable('layout')); + // page section or layout mapping + $section = $config->getLayoutSection($page->getSection()); switch ($page->getType()) { case PageType::HOMEPAGE->value: @@ -112,9 +114,9 @@ protected static function lookup(CollectionPage $page, string $format, \Cecil\Co "_default/list.$format.$ext", ]; if ($page->getPath()) { - $layouts = array_merge(["section/{$page->getSection()}.$format.$ext"], $layouts); - $layouts = array_merge(["{$page->getSection()}/list.$format.$ext"], $layouts); - $layouts = array_merge(["{$page->getSection()}/index.$format.$ext"], $layouts); + $layouts = array_merge(["section/{$section}.$format.$ext"], $layouts); + $layouts = array_merge(["{$section}/list.$format.$ext"], $layouts); + $layouts = array_merge(["{$section}/index.$format.$ext"], $layouts); } if ($page->hasVariable('layout')) { $layouts = array_merge(["$layout.$format.$ext"], $layouts); @@ -156,13 +158,13 @@ protected static function lookup(CollectionPage $page, string $format, \Cecil\Co if ($page->hasVariable('layout')) { $layouts = array_merge(["_default/$layout.$format.$ext"], $layouts); } - if ($page->getSection()) { - $layouts = array_merge(["{$page->getSection()}/page.$format.$ext"], $layouts); + if ($section) { + $layouts = array_merge(["{$section}/page.$format.$ext"], $layouts); } if ($page->hasVariable('layout')) { $layouts = array_merge(["$layout.$format.$ext"], $layouts); - if ($page->getSection()) { - $layouts = array_merge(["{$page->getSection()}/$layout.$format.$ext"], $layouts); + if ($section) { + $layouts = array_merge(["{$section}/$layout.$format.$ext"], $layouts); } } }