1
votes

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.

1

1 Answers

0
votes

I'd use the PageList class which is much more flexible

$c = Page::getCurrentPage();
$pl = new PageList();
$pl->filterByParentID($c->getCollectionID());
$subPages = $pl->get(0);

Not quite sure what errors you're receiving, I'd assume it's because of missing JavaScript and CSS files. That would happen because those scripts aren't associcated with the current page and thus not included in the header.

If that happens to you, here's an example showing you how to do that, takes a few lines of code: https://github.com/mkly/area_from_another_mother/blob/master/blocks/area_from_another_mother/controller.php#L313-L359