Let’s assume your above structure
1_ banana-page
fruitpage.txt
/banana-info
info.txt
/banana-gallery
gallery.txt
/banana-whatever
whatever.txt
2_orange-page
fruitpage.txt
/orange-info
info.txt
/orange-gallery
gallery.txt
/orange-whatever
whatever.txt
3_guave-page
fruitpage.txt
/guave-info
info.txt
/guave-gallery
gallery.txt
/guave-whatever
whatever.txt
These three first level pages all share the same blueprint fruitpage.yml
and the same template fruitpage.php
They all have the same three types of subpages which are used as the three sections of their parent page. For these subpages, we need three blueprints (info.yml
, gallery.yml
and whatever.yml
) and three snippets (see below). We do not need templates for them at this moment, unless we also want to render them as single pages. Then we can create additional templates for them. e.g. if you only want to show an excerpt on the fruitpage and more info in a separate page.
Now for the fruitpage.php
template. In this template, we want to display the title of the page, maybe some text and the three subpages:
<?php snippet('header') ?>
<h1><?= $page->title() ?></h1><!-- This will render "Banana" in case of the banana page or "Orange" in case of the orange page etc. -->
<?= $page->text()->kt() ?>
<!-- now for the three sections -->
<?php foreach ($page->children() as $child) {
// we call their snippets using the intended template as their name
// and pass the child page as variable
snippet($child->intendedTemplate(), ['section' => $child]);
}
?>
<?php snippet('footer') ?>
(intendedTemplate()
: https://getkirby.com/docs/reference/objects/page/intended-template)
Now we need the three snippets
- site/snippets/info.php
- site/snippets/gallery.php
- site/snippets/whatever.php
These have the same name as the corresponding text files of the subpages.
Example content for the info.php snippet, here we use the $section
variable for the subpage which we passed above.
<h2><?= $section->title()->html() ?></h2>
<?= $section->text()->kt() ?>
Similar and depending on defined fields for the gallery and the rest. The snippets fetch the content from the subpages content files. What exactly you render in each snippet depends on the fields you have defined in each blueprint.
This way, we can create as many of the same types of pages as we want that all share the same structure, but their actual content differs.
We can also create variants by changing the order of the sections etc.
The procedure is actually the same as for one-pager sites, with the difference that we implement it for multiple parent pages.
IMO, the most important step when creating a new project is planning. Thinking about the content structure of your site, what content each element needs etc. The better your structure and your plan, the easier it will be to implement everything later and you will have a lot less work with changes.
Worth watching: