dersven
December 17, 2021, 2:28pm
1
I use the following proven syntax for displaying the snippets for the sections of my one-page configuration. that works great:
<?php foreach($pages->listed() as $section): ?>
<?php snippet($section->uid(), ['data' => $section]) ?>
<?php endforeach ?>
now i have set up the site in a way that there are subpages which, should also use the same sections as on the root-level with home.
so the pages in the 3rd level are also the sections that should be displayed: how can the code be changed so that it works?
<?php foreach($pages->template('coaching')->children()->listed() as $section): ?>
<?php snippet($section->uid(), ['data' => $section]) ?>
<?php endforeach ?>
thanks for helpful tips-
texnixe
December 17, 2021, 3:14pm
2
I’m not really following your setup. Could you please post an outline of your folder structure?
And in which template are you trying to use the second code snippet?
dersven
December 20, 2021, 12:18pm
3
a bit confusing. – i tried my best to sketch my folder structure.
in level 1 the elements for the sections are running yet.
for a subpage in level2 - i would use the same elements as sections.
so i copied these pages as subpages for the level-2.
but if i use the data-snippet-thing i get no content.
the elements are subpages in level 3
and the second code-snippet have to work here in level 2
is that a bit more understandable?
texnixe
December 20, 2021, 12:25pm
4
What do you get when you
dump($pages->template('coaching')->children()->listed());
dersven
December 20, 2021, 12:44pm
5
i getting:
Kirby\Cms\Pages Object ( )
maybe its not the best struture?
my subpages level 2 with the template ‘coaching’ have subpages with the templates ‘textwithimage’ or other sections-elements.
is this concept right?
have i go on »blocks« - for easier setup?
texnixe
December 20, 2021, 1:19pm
6
But $pages
refers to the first level pages unless you redefined this variable somewhere, that’s why your collection is empty.
Where exactly in your tree are you calling this snippet?
dersven
December 20, 2021, 1:31pm
7
i have a page in level 2 named ‘Coaching1’ with the template ‘coaching’
and on this template i call this snippet for the subpages as section-elements.
one level up, is root – and my example-page ‘coaching1’ ist a subpage of coachings (like projects in the demo structure)
dersven
December 20, 2021, 1:35pm
8
with
<?php foreach($pages->children() as $child) {
echo $child->title()->html();
} ?>
i get all subpages of level2
now i want to get only the children of template ‘coaching’. but ->template(‘coaching’)
<?php foreach($pages->children()->filterBy('template', 'coaching') as $child): ?>
<?php echo $child->title()->html(); ?>
<?php endforeach ?>
that is working.
next step is to get by uid the right snippet to output the subpage:
<?php snippet($child->uid(), ['data' => $child]) ?>
but this does not work #schnief
texnixe
December 20, 2021, 2:58pm
9
IMO, if you are in the coaching template, you should simply get the children of that page:
foreach($page->children()->listed() as $section) {
// do stuff
}
Don’t know what you want with the $pages
variable there.
dersven
December 21, 2021, 8:49am
10
oh how great, now it’s going as i thought. how easy, $ page instead of $ pages.
<?php foreach($page->children()->listed() as $section): ?>
<?php snippet($section->uid(), ['data' => $section]) ?>
<?php endforeach ?>
that outputs all subpages / level3 on page level2. yeah!
1 Like