Snippet confusion: why is the header a "re-usable" snippet?

Hi,

I’m getting to learn Kirby, and is’t very interesting.

One thing confuses me: why is header.php (which is the same for each-and-every page) a re-usable snippet?

Now in every template.php there is code-duplication which is

<?php snippet('header') ?>

Is is possible to have one index.php file for example, with the fixed header and the footer, and a place where the dynamic content is loaded into?

Thanks,
Klaas

The way Kirby works, it is not possible. The name of the content file determines the intended template, which needs to have everything in it, including the header and footer.

If you have a very simple site structure that does not need many different templates, you could create only one default template with the header and footer snippet and page snippets for different pages (using if statements). But then you would have to put all the logic into one default controller as well.

I think it makes sense the way it is. By including the header/footer snippets you actively decide what markup you want to output. Many other CMSs have a presumption there to force a specific structure or even markup.

Let’s say you need a RSS feed or you want to dynamically generate an SVG with Kirby. It wouldn’t be possible if the HTML header was included by default.

Some time ago, @bastianallgeier posted a short teaser showing how an integration with established template systems could be realized. I’m wondering wether this approach will be continued as it would enabled everyone to use or not use the template system of his choice.

Ok, thanks, good point.

Not every web page has the same header in my kirby websites.
You may want to look at HowTo: Insert additional rows in the HEAD of a template file for details, how to switch easy for a different <head> part for a web page.
Some pages may need a special CSS file or a special JS file…


Look at Kirby dosc: Templates > Your first template, if you don’t want to use snippets. But that is not my suggestion to you.