pwired Posted January 5, 2016 Share Posted January 5, 2016 Hi,I am using child pages to output different areas for the parent pageHere is an example and this works very good: (original idea from Diogo) <section id="area1"> <?php echo $pages->get("/home-areas/home-area1/")->render()?> </section> <section id="area2"> <?php echo $pages->get("/home-areas/home-area2/")->render()?> </section> To view the different areas, the html formatting needs to be done on the template files of the child pages.Would it be possible to use something like wireRenderFile() on child pages so I won't needthe template files for the html formatting but instead an external html file in /templates/layouts/ ?Obviously this does not work: echo $pages->get("/home-areas/home-area1/")->wireRenderFile(path/to/html);But maybe another way ? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 5, 2016 Share Posted January 5, 2016 I don't get why you want to use wireRenderFile when you have a template to work in. What I often do in a template is: $body = ''; if (count($page->pagetable_content)) { foreach ($page->pagetable_content as $row) { $row->set('source', $page); $body .= $row->render(); } } And then on the rendered page ($row) // No direct access to this page, loaded via page table. if (!($page->source instanceof Page)) { throw new Wire404Exception(); } This way my rendered page is protected for direct viewing and I have access to the 'original' page via $page->source. 2 Link to comment Share on other sites More sharing options...
pwired Posted January 5, 2016 Author Share Posted January 5, 2016 I don't get why you want to use wireRenderFile when you have a template to work in. Every child page that needs a different look needs it's own template file. If you add those template files to the template files for the parent pages you end up with a lot of template files. I was trying not having to use template files for child pages for the needed html format. Link to comment Share on other sites More sharing options...
pwired Posted January 5, 2016 Author Share Posted January 5, 2016 By the way your code makes smart use of pagetable and render() never thought about it to have a page accessable like this. 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 5, 2016 Share Posted January 5, 2016 When I need the same fields on the child pages but diffent layout, I usually go for FieldtypeSelectFile. With that field you can select a file from the PageEdit (admin) to be used as a template. 1 Link to comment Share on other sites More sharing options...
pwired Posted January 5, 2016 Author Share Posted January 5, 2016 Thanks for pointing me to that module, I will give it a try. Another option could be to find a balance between using pages with wireRenderFile() and pages with children to output different areas as the latter is only needed in some pages. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 5, 2016 Share Posted January 5, 2016 You could use wireRenderFile, if wished Nothing wrong with it. Link to comment Share on other sites More sharing options...
clsource Posted January 5, 2016 Share Posted January 5, 2016 You could use wireRenderFile() inside child pages as well Just you need to create the different layouts. site/ templates/ views/ home-area1.php home-area2.php home.php For each child create a template ex: home-area1, home-area2 assign that template to every child. then in home you could use the template name for rendering the file $sections = $pages->get('template=sections'); $viewBag = getViewBag(); foreach($sections->children as $section) { $viewBag['section'] = $section; try { echo wireRenderFile("partials/home/sections/{$section->template->name}", $viewBag); } catch(Exception $e) { Debug::log($e->getMessage()); } } ?> 1 Link to comment Share on other sites More sharing options...
Recommended Posts