Rendering child pages
Created 7 years ago by sir_vince

In an effort to ease construction of complex pages have I run into the need to render child pages. What I'm trying to accomplish could be described as the following: {% for child in page.children %} {{ child.render() | raw }} {% endfor %}

And what would happen here is the layout of the given child page is rendered with all the values set for the given page. Am I just missing something or is this not part of the design?

Thanks

ryanthompson  —  7 years ago Best Answer

Try {{ child.content()|raw }}

sir_vince  —  7 years ago

Wow, that was fast, and it worked. I tried {{ child.content | raw }} which just translated to the content field but didn't think to call it as a function.

Thanks 😄

ryanthompson  —  7 years ago

You won't be able to do this in the layout though I don't think because of recursion.. It'd be in the page content somewhere. Maybe a page type and slap it in an editor field. Ill checkout how to avoid the recursion but.. content uses the type layout so it's not really avoidable most likely.

A simple example out of the box (2 = the contact page that's seeded but you could use your loop too):

<p>Welcome to PyroCMS!</p>

{{ page(2).content()|raw }}