我正在尝试实现一个Concrete5主题,它将所有子页面加载到主(索引)页面中。到目前为止,我只是循环遍历我的子页面数组,获取类型、上下文(区域等),然后用每个页面的页面模板标记加载一个元素。不幸的是,这很容易出错,而且肯定还有其他方法--下面是我的主页标记:
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);
}页面类型如下所示:
<?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'); ?>Loader::()引入的layout元素看起来像这样(只是普通的旧HTML和Concrete5区域片段):
<section id="<?=$page->vObj->cvHandle; ?>">
<div class="whatever">
<?php
$a = new Area($page->getCollectionName() . ' Page Content');
$a->display($page);
</div>
</section>这在很大程度上是有效的,但是我似乎仍然在加载块时遇到一些错误,等等。所以我不确定是否有更好的方法在使用Concrete5的同时获得“单页面”主题。我想知道是否有其他人有构建这种类型的主题的经验,或者是最好的方法。
任何帮助都是非常感谢的。
发布于 2015-06-19 18:14:48
我会使用PageList类,它更加灵活
$c = Page::getCurrentPage();
$pl = new PageList();
$pl->filterByParentID($c->getCollectionID());
$subPages = $pl->get(0);不太确定你收到了什么错误,我假设是因为缺少JavaScript和CSS文件。这是因为这些脚本没有与当前页面相关联,因此没有包含在页眉中。
如果这种情况发生在您身上,下面是一个示例,向您展示如何做到这一点,只需几行代码:https://github.com/mkly/area_from_another_mother/blob/master/blocks/area_from_another_mother/controller.php#L313-L359
https://stackoverflow.com/questions/27511254
复制相似问题