[Solved] How to fetch content from subpages with different templates

Hello everyone,
i have following structure example

- master-folder
  master-template.txt

-- subfolder-alpha
   template-a.txt
-- subfolder-beta
   template-a.txt
-- subfolder-gamma
   template-b.txt
-- subfolder-delta
   template-b.txt

I got it how to get content from subpages en general, but how i can separate snippets in master-template.php so I can fetch content from first two subfolders with template a, than to fetch content from folders with template-b etc.?

Use $subpage->template() or $subpage->intendedTemplate() to decide which snippet to load.

http://getkirby.com/docs/cheatsheet/page/template
http://getkirby.com/docs/cheatsheet/page/intendedTemplateFile

Or if you want to include the actual template files (not sure if I would - sounds rather like a case for snippets):
http://getkirby.com/docs/cheatsheet/page/templateFile
http://getkirby.com/docs/cheatsheet/page/intendedTemplateFile

Hello Nico,
thanks for answer!

Actualy I would include it as snippet.

So, are you suggesting, that when I use template() it should be something like this:

<?php foreach(page()->children()->template(template-a) as $page): ?>
...
<?php endforeach ?>

then

<?php foreach(page()->children()->template(template-b) as $page): ?>
...
<?php endforeach ?>

I am pretty sure I did it wrong because it’s not working :smiley: but how to use it right?

template is a field of the page, not a filter itself. So you have to filter using filterBy:

<?php foreach(page()->children()->filterBy('template', 'template-a') as $page): ?>
...
<?php endforeach ?>

More documentation on filters: http://getkirby.com/docs/cheatsheet/pages/filterBy

I am seriously impressed of you both for such quick replies - it worked! If we, by any chance, meet, you can count on a free drink.

well, somehow you have to avoid doing actual boring work for uni :wink: