Hi there,
So I built this One-pager for a customer how it’s described on the Kirby-Website, but if I wanna add a new page / section trough the panel, it won’t be displayed or rendered in the html on the website, but in the panel list.
Since i’m new to Kirby and just an intermediate Front-end dev. I really don’t know where to start digging.
Are there any things I overlooked besides creating templates for each section?
The website is live on http://esdar-enegry.com .
If you need any further information let me know, I’d be happy to get some response <3
if you work with subpages and snippets,
make sure to check if each individual subpage has the correct template.txt, as well as having the matching template.php within /site/templates/ even if it’s just a redirect to avoid direct access.
what i usually like to do is:
- create blueprint, template and folder+txt in one go, so you won’t forget about it later, thus it’s easier with blueprint as you have set up your matching fields…
1 Like
Thanks for the quick response Carsten!
So I have to drop a template.txt in each folder?
Can this be generated if i create a new section through the panel?
You will need:
site/blueprints/yoursnippet.yml
– which has informations about what fields are available for entry in panel (this is optional)
site/templates/yoursnippet.php
– which will be called if someone tries to access the sub-content-page directly (no template file will make the sub-content as not existing)
content/sub-folder/yoursnippet.txt
– which is the actual content file
site/snippets/somesnippet.php
– this is where you program what should happen when you use
<?php snippet('somesnippet.php') ?>
as example:
<?php
foreach(page('something-for-snippets')->children()->visible() as $children):
// Do something here....
endforeach; ?>
in this case make also sure that your content is set to visible.
…
snippets can really be anything, while the above will only work with content files a snippet could also just something like an include which you use at multiple locations. maybe you post some of your code so we can see what is going on?
If you have followed along the one-pager tutorial, the snippets for the pages that make up the different sections of the one-pager are called by their UID. But the UID for each page has to be unique. As a consequence, there will be no snippet for additional pages you might add.
For what you want to achieve, i.e. repeating snippets, I’d recommend using the Modules plugin.
But of course, it can also be achieved with native methods, but then you have to tell Kirby which snippet to use. The intendedTemplate()
method is helpful in this case:
<?php
foreach(page('section-parent')->children() as $page) {
snippet($page->intendedTemplate());
}
?>
To add more for your choice.
<?php foreach($pages->find($page->landing())->children()->visible() as $feature){
snippet($feature->template(), array('data' => $feature), true);
} ?>
array argument draws all fields into the snippet being able to call it via
echo $data->field();
this has worked for me.
- blueprints for field information (blueprint folder example.yml)
- template redirect to home (templates folder example.php)
- snippet usually is html + field output (snippet folder example.php)
so usually i have several diffrent templates such as
- landing.top
- landing.wide.image
- landing.three.columns
etc.