I'm trying to implement a Concrete5 Theme that loads all subpages into the main (index) page. So far, I'm, just looping through my child pages array, grabbing the type,context (areas, etc), and then loading an element with the page template markup for each page. Unfortunately, this is highly error prone, and there must be another way - here is my main page markup:
global $cp;
if(!$cp->canWrite()) {
$childPages = $c->getCollectionChildrenArray(1);
foreach($childPages as $childPage) {
$page = Page::getByID($childPage);
$cPages = $page->getCollectionChildrenArray(1);
if($cPages) {
$parentPage = $page;
$page = $page->getByID($cPages[0]);
}
$layout = $page->getCollectionTypeHandle();
$context = array('page' => $page);
if(!$layout) {
continue;
}
Loader::element('layouts/' . $layout, $context);
}
A Page type looks like this:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php $this->inc('elements/header.php'); ?>
<?php
global $c;
$context = array('page' => $c);
Loader::element('layouts/case_study', $context);
?>
<?php $this->inc('elements/footer.php'); ?>
And the layout element that Loader::() is pulling in looks like this (Just plain old HTML and Concrete5 Area snippets):
<section id="<?=$page->vObj->cvHandle; ?>">
<div class="whatever">
<?php
$a = new Area($page->getCollectionName() . ' Page Content');
$a->display($page);
</div>
</section>
For the most part this works, however I still seem to bump into some errors when loading blocks, etc... so I'm not sure if there is a better way to get a 'single page' theme while using Concrete5. I was wondering if anybody else had experience building this type of theme, or the best way to go about it.
Any help is appreciated.