Creating a one-pager with subpages

Hey there,

I am trying to transfer a website into the Kirby CMS and ran into some problems with the overall structure of the site.
The website is about an university course and the site I am talking about is this one:

My problem is kind of related to those:

Because I am really new to Kirby I am trying to figure out if I am doing it right or if there is a fundamental wrong approach in setting this site up. I try to explain my process of thought:

  • After the slider i got 3 of the same content types. I call them content-blocks. I want to reuse those content-blocks in all of the different sections.
  • The site is divided by sections like “Study, University, …, Apply” etc. where you can scroll to. Content-blocks can be created in every one of those sections. For each one of those sections I created a snippet (followed along the kirby solutions here:
  • Each of those snippets yields a page which should be able to create subpages where you can chose from a template: e.g: "content-block, content-table, arrowed-list, … " etc. like you can see in this picture.

  • My folder structure looks like the following:

Now I want to fetch all my sites with its different subpages in the home.php file and display them. I do this like the following:




foreach($pages->visible() as $section) {
  snippet($section->uid(), array('data' => $section));



Then I iterate over the visible pages in study.php

foreach(page('study')->children()->visible() as $content):
  snippet('contentBlock', array('data' => $data, 'content' => $content));

However if I add

snippet('contentBlock', array('data' => $data, 'content' => $content));

to the foreach loop I will of course get a false result, because there is not a content-table for every visible page on my site and I will get something like this:

As you can see I have some troubles in understanding of what would be the proper approach in the overall setup of the site. I want the editors to be able to add different types of content in the different sections of the page. However I don’t know how to fetch all sub pages like: for all pages on the site get each of their individual sub pages and render them to view.

At the moment the panel is choosing the “contentBlock” template from the snippets folder? How can I change that, so that I can create it in the template folder and the different pages are referring to it?

I hope you can provide me with some help.

Kind regards,

First of all, do not use camelCase in filenames, only small letters to prevent problems on different platforms. So pls. change “contentBlock.php” to “contentblock.php” etc. (and all the text files as well).

Secondly, you can use a variable to fetch the different sorts of snippets required for each subpage using the intendedTemplate() method like this:

foreach(page('study')->children()->visible() as $content):
  snippet($content->intendedTemplate(), array('data' => $data, 'content' => $content));

That should fetch the contentblock snippet if the text file is called contentblock etc.

Hope this helps for a start.

You’re my hero :slightly_smiling: .
I think it took me 1.5 hours to write my question and you helped me solving it in under 5 minutes.

I hope I can move forward now and finish the site appropriately but for now it works

1 Like

You are welcome. Don’t hesitate to ask if you get stuck again. We are here to help :slightly_smiling: