I want to use subpages as sections (like a one pager) on various pages. I managed this piece of code which gives me the text fields of the subpages:
<?php if ($page->subpagesVisibility()->isTrue() && $subpages->isNotEmpty()): ?>
<?php foreach($subpages as $section): ?>
<?php echo $section->text() ?>
<?php endforeach ?>
However, the subpages have different templates, different panel fields for e.g. bg-image, gallery, video url. This why I want to fetch the created html of the subpage altogether.
Is there a code which delivers the whole html of the subpage and not only the text?
While your approach with using templates is certainly possible, there is a downside to it: you cannot structure your templates in subfolders. So if you have a lot of such one-pages pages with a lot of subpages, you might quickly end up with a lot of templates.
That’s why in the one-pager cookbook, we use snippets for the html of such subpages. Snippets can be organized in folders.
The problem with the code @jimbobrjames provided, is that it loops through all the main pages. You probably only want to loop through the children of the given page:
Oh sure…its merely a starting point. The source of the data to loop through is upto @nedimbora - it certainly worked in the project i tried it in before posting. I probably should have made that clearer.
But as @texnixe said this isnt the ideal way to go - the soloution described in the cookbook article I shared to start with is the best thing to do.
I see. The site i did it on (https://theworkofothers.com/) uses a different template for the home page and the subpages. I rendered about 10 of them into the home page just fine (albeit with duplicate html, head, and body tags - you need to omit these in your subpage templates in reality), but i guess thats why it worked ok.
In otherwords, the snippet way is definitly the way to go