3 times a blog. How to make 3 pages with 3 sections dynamic?

This is perfectly fine with a proper content wise setup. I think, in the short term it is valid to see it like this. In mid- to longterm view it will become a problem:

  1. You have to manage more and more content in an less optimal way,
  2. it will be hard to find designers or content managers who can work with this,
  3. It will be harder to find errors or bugs in your code/site, when they occur and you look for the reason/source of the problem and last but not least
  4. Other people can help less/way harder because they don’t expect your setup to be like this and there might be lot of undocumented/uncommon implementations which are hard to understand without a complete view on the whole project every time you have an issue.

So yes, it is a way to start or to test how things work but it will raise issues and complexity very quick and this should be prevented at the most earliest stage to make your own life easier. Otherwise your current problems or questions will look like tiny ones compared to what might come next lol.

@warg
You are right. I am running another project like this, that in 1,5 years has grown to quite a size - all without a CMS! All because I had to jump start that other project and never found the time to learn and install a CMS. And of course at a certain point it is too late. Since I am the only designer, developer, content manager and author on it, I hand coded every text, image, video or any gimmick into it - and still do. My CMS is copy, paste and debug. The result is that the code for that site is huge and not well organised.

That’s the reason, I want a CMS on this one, because I learned that lesson. It is just, that I am (sadly) not a professional developer or designer and not a natural talent in code.

1 Like

If I use 1 template for every fruit page - how can I control where the content goes? How can I pull an info article for banana into the „banana info section“ on the banana page or a photo of a guave“ into the guave-photo section on the guave page?

With a select field?

And how can I make section on the start page in the panel to visually structure the possible content authors?

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:

Now this blows me completely away!

Your answer came in the exact moment, that I wanted to give up, since I am trying to figure this out since 2am and all the last days. I tried to use just 1 template and ended up adding even more files for everything than before.

But all this had a good side to it, because I understand what you are telling me, because I ran against exactly the walls, that you put doors into right now.

And:

I didn’t know that there are videos now!!! I never imagined they would exist one day!

Now - I am going to dive in it right now… !

The videos are quite new and a new test/idea of @bastianallgeier. There’s a new forum category for them:

No. I am sorry. I still can’t figure it out. I am too stupid for this. My brain just doesn’t work that way.

I have the wrong blueprint setup for the fruitpage.yml and I can’t figure out which is right.

I have the wrong bluepirnt setup for everything and I can’t figure it out.

Why do I have to put in the content folders and its subfolders manually first? Because when I do it, confuses everything. When I throw them out, the panel puts new ones in, when I make a page. I guess, that is how it is intended, but I am unsure because in the cookbook and in your answer above, you start with the folder structure. Is it for to show the structure? I am confused.

Sometimes I have duplicate content in all sections.

All I have right is the headline.

It’s to show the structure and because it’s easier to explain in a short guide how to create the example content via filesystems rather than to explain how to do it via panel. Furthermore you have to specify blueprints to be able to create content via the panel and this is not a requirement for Kirby 3 to work - it’s nice to have but optional. So yes, you can start with blueprints and do the content via the panel. That’s how I do it too.

Depending on the guide you look at, it’s either focused on the Panel/Blueprints, the content and how to store it properly or about templating/designing the frontend of the page. Thus sometimes the blueprint part isn’t described but the folder structure and the content of the page files. That’s why I was confused at the beginning too regarding why sometimes it starts with page files like this!

You can also start with the blueprints, but it usually doesn’t make that much sense to create blueprints if you don’t know what structure you want for your site.

If you want to start with the Panel to create your pages, you need:

  • a site.yml blueprint with (at least) one section for all your main pages, most simple setup:
title: My fruity site
preset: pages

This will give you a dashboards that displays all first level pages in the site

  • the fruitpage.yml blueprint, with this in place, you can then create your first level fruit pages via the template if you select this one in the create dialog

The fruitpage.yml blueprint could then look like this

title: Fruitpage

columns:
  main:
    width: 2/3
    fields:
      field1:
        label: Label
        type: textarea
      # maybe more fields here

  aside:
    width: 1/3
    sections:
      subpages:
        type: pages
        headline: Page sections
        templates:
          - info
          - gallery
          - whatever

This allows you to create subpages with one of the three given templates in the pages section.

What you put into the info, gallery and whatever blueprints then depends on the content structure you need there. This can be very basic with just a set of fields or with sections for different types or files etc.

Again, here we are again at the point that creating the blueprints and knowing what should go into them requires (if not the physical page folders and files themselves) at least an idea of the structure of the site.

1 Like

Ok something worked here. But I get content duplicates.

Does this:

<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') ?>

work as a sort of container for all snippets? It feels like it. I get two identical sections with the same content. One with the headline of infos an done with the headline of news.

My intention was to produce this structure:

INFOS ABOUT BANANAS

First info about bananas
Info yellow Excerpt
link to article

Second Info about Bananas
Info green Excerpt
Link to article

Third Info about Bananas
Info red Excerpt
Link to article

NEWS ABOUT BANANAS

First news about bananas
Info pink Excerpt
link to article

Second news about Bananas
Info purple Excerpt
Link to article

Third news about Bananas
Info black Excerpt
Link to article

But I get:

INFOS ABOUT BANANAS

First info about bananas
Info yellow Excerpt
link to article

Second Info about Bananas
Info green Excerpt
Link to article

NEWS ABOUT BANANAS

First info about bananas
Info yellow Excerpt
link to article

Second Info about Bananas
Info green Excerpt
Link to article

In your first post, you had outlined three sections:

  • infos
  • pictures
  • news

What I outlined above is based on this information.

If your info section should have multiple parts, you can either Crete multiple subpages with the same blueprint or provide them as subpages to the info pages or by putting this content into a structure field.

That depends what is in your snippets, or maybe you have chosen the same blueprint for those sections (since I don’t see your content folder from here, I can’t tell).

The idea of the foreach loop is to loop through all subpages of the fruit page and render them using the snippets that is assigned to it by the name of the text file in its page folder.

Could you please post your content structure (i.e. a screenshot of the content folder with the relevant subfolders all open so that we can see what is in there), the results do not tell me much.

Bildschirmfoto%2013

oh, “all open”. Just a minute. Sorry

Bildschirmfoto%2014


With “all open” I mean I also would like to see all subfolder with their subfolder and the text files in the subfolders like this:

(I haven’t opened all in this example but you get the idea)

I assume über, freenow and clevershutttle are your fruits.