Jump to content

wireRenderFile() on child pages


pwired
 Share

Recommended Posts

Hi,

I am using child pages to output different areas for the parent page
Here 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 need
the 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

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.

  • Like 2
Link to comment
Share on other sites

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

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

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());
	}
}
?>
  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...