Reuse snippets in one-pager

#1

I want to enable my client to create new subpages within the site. As I am using snippets and not templates, like suggested in the cookbook, it does not seem to work like I thought it would.

There are several threads about the topic already, suggesting to use intendedTemplate but the solution didn’t work for me / I didn’t understand it.


Lets say this is my content folder (I have no sub-folders within the content folder)

1_adventure
	adventure.txt
2_super_adventure
	adventure.txt
3_about
	about.txt
4_general
	general.txt
5_even_more_adventures
	adventure.txt

I want 1_adventure, 2_super_adventure, 5_even_more_adventures to use the same blueprint and php-snippet.

This php code from the cookbook worked until I noticed that I could re-use the snippets…

<?php foreach($pages->listed() as $section) {
  snippet($section->uid(), ['data' => $section]);} ?> 

Using intendedTemplate like below results in a empty page

foreach(page('home')->children() as $section) {
  snippet($section->intendedTemplate()); } ?>

So how to fix this last snippet?

Thanks in Advance!

0 Likes

#2

You still have to pass the variable array.

foreach(page('home')->children() as $section) {
  snippet($section->intendedTemplate(), ['data' => $section]); 
} ?>
0 Likes

#3

Unfortunately it doesn’t work. The result is a empty page, respectively a empty div.

0 Likes

#4

These pages are are children of the home folder? Because

this sounds a bit contradictory. Are those pages above now children of content or children of home?

0 Likes

#5

Sorry, if I wasn’t clear enough. All pages are children of content.

content
	1_adventure
		adventure.txt
	2_super_adventure
		adventure.txt
	3_about
		about.txt
	4_general
		general.txt
	5_even_more_adventures
		adventure.txt
	error
		error.txt
	home
		home.txt
	site.txt

But content or site instead of home give me an error.

0 Likes

#6
foreach($site->children()->listed() as $section) {
  snippet($section->intendedTemplate(), ['data' => $section]); 
} ?>
0 Likes

#7

Thank you @texnixe
So simple!

0 Likes