Fetching content from subpages as snippet

Hey there, i’m trying to setup a blog with some needed features just as mentioned in [this topic] (Kirbytext tags and HTML structure)

There was this nice solution with subpages as modules and i’m trying to achieve this kind of structure. But i don’t get what i am doing wrong. My code for this content looks like this.

<section id="content">

		<?php foreach ($page->children() as $p): ?>
			<?php snippet($p->intendedTemplate()); ?>
		<?php endforeach ?>		
	</section>

You got any suggestions on what i’m doing wrong? Thanks for any help.

Greets Tobi

Do the snippets exist? Do the names of the text files of the child pages match the snippet names?

Hey thanks for the quick answer. No there was no snippet before. The subpage i created had the template text.php (simple text field as module). That’s how i named the snippet then too, but still nothing happens. Maybe it’s because of two-language-installation? Could you give me a heads up on how to accomplish what i want to do?

Thanks so far.

Tobi

Could you pls. post a brief outline of your folder structure, the names of the text files and the names of the snippets exactly as they exist in your folders?

The text files must, of course, have the language extension, i.e. named text.de.txt, text.en.txt etc. and should not have an additional text.txt in it.

Hey texnixe, this is my current structure. Since it is not live the sites have testnames:

3-blog (startpage of the blog-section)
– 2-testeintrag (article page)
– – 1-testeintrag-text01 (first module inside page as text-module)
– – – text.de.txt
– – blogentry.de.txt
– – blogentry.en.txt
– blog.de.txt
– blog.en.txt

That’s it so far. You get what i want to accomplish?

Greets Tobi

I think what’s missing here is that you need to pass the right variable to the snippet:

<?php 
  foreach($page->children() as $p) {
   //provided you page variable is called $page in the snippet, you need to pass $p to $page in the snippet
    snippet($p->intendedTemplate(), array('page' => $p));
  }
?>

Unfortunately it’s not working and breaks the code. I put your code inside my blogentry.php-template and have my text.php inside the snippets-folder.

the section in the blogentry.php-template looks like this:

<section id="content">
		<?php 
		  foreach($page->children() as $p) {
		   //provided you page variable is called $page in the snippet, you need to pass $p to $page in the snippet
		    snippet($p->intendedTemplate(), array('page' => $p));
		  }
		?>	
	</section>

and my text.php inside the snippets-folder looks like this (quite simple snippet):

<div class="wrapper">
	<?php echo $page->text()->kirbytext() ?>
</div>

anything i did wrong? is it important what’s inside the text.php of the template-folder?

Oh, I named the variable $child first and then changed it to $p to make it fit with your code, only I forgot the change it in one location, so it should be like this:

<?php 
  foreach($page->children() as $p) {
   //provided you page variable is called $page in the snippet, you need to pass $p to $page in the snippet
    snippet($p->intendedTemplate(), array('page' => $p));
  }
?>

You should really turn on debugging in your config.php to find this kind of error.

c::set('debug', true);

Thanks for the help. I turned debug on, it’s really helpful. The code in your latest reply seems to be wrong, as you wrote. But in the reply from 1h ago this code works good. Just had to change the $child-variable througout the code. This is working:

<?php 
  foreach($page->children() as $p) {
   //provided you page variable is called $page in the snippet, you need to pass $p to $page in the snippet
    snippet($p->intendedTemplate(), array('page' => $p));
  }
?>

Thanks for that i keep you up to date, how the modules-stuff is working out!!

Have a nice weekend. Tobi