How to add the complete frontend output of a template or snippet to my home template?

Hello, I’m new to Kirby CMS and worked by viewing the videos on a first site with the plain installation.
So far there is the home site that should show events as content. The events are in the subdirectories of home. With this code I can get parts of the existing events.

  <?php foreach($page->children() as $subpage): ?>
	<li>
    <a href="<?= $subpage->url() ?>">
      <?= html($subpage->title()) ?>
    </a>
  </li>
  <?php endforeach ?>

The events have their singleview template with all the html, that is needed fore each event on home site too. But I don’t know how to get the complete output of the event, like if they are shown in single view template, to the home site?

If I’ll get this to work, I don’t know how it is possible, that the subdirectories of (home) should not be accessable with url, because they are just containers for each event. There is no need of a single view, because all is then shown on home site

I’m not shure if my current strategy with subdirectories in home is best way of doing this, because for now it works, but afer some years the events should be grouped in directories like 2022, 2023, 2024, each with subdirectories of the yearly events.
If you have any suggestions to get a good stragety to manage this better, I would be glad.

Well, 3 questions in one post. But the first ist the important question for me at the moment.

Thanks

Then the events don’t need a template.

I’d create a snippet for the events, which you can then call in your loop.

Hello Sonja, that’s it.
For anyone with the same question. On my site I use event instead of article.

  1. Use a snippet as a loop in templates
  <?php foreach($page->children() as $event): ?>
  <?php snippet('event', ['event' => $event]); ?>
  <?php endforeach ?>
  1. Example part of snippet (here named: event.php):
<div class="event_headers event_topwrapper_child">
        <h2 class="h2-1"><?= $event->title()->html() ?></h2>
        <h3 class="h3-1"><?= $event->subtitle()->html() ?></h3>
 </div>

And yes, by removing the template fore the events there is no url directing to any event. No need of extra stuff.
I’ll finish now all fields in the snippet and then try to use a better structure for events…
Tahnk you and good evening.

Even if you don’t have a URL that points to the page, each page folder is by default accessible via a URL. If you want to avoid that someone lands on such a single page by chance, you can either add a redirect in a template (for that you would have to reintroduce the template) or, better (because you don’t need an otherwise useless template) use a route that does the redirect.

hmm… What do you mean with “use a route that does the redirect”?
via htaccess?

.htaccess would be an option, yes, but I meant:Routing | Kirby CMS

In your config, within the return array, you would add something this route:

/site/config/config.php

return [
    // …other settings
    'routes' => [
      [
        'pattern' => 'home/(:any)',
        'action'  => function () {
            go('home');
        }
      ]
    ]
];

This route runs when someone tries to access a subpage of the home page, e.g. yourdomain.com/home/some-subpage, and then sends them to the home page (alternatively, you could send them to the error page).

cool!