在使用Area Splitter插件输出标记之前,是否有方法检查子区域是否包含块?
一直在尝试这样的东西,但不知道如何让它发挥作用对不起:
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$c = Page::getCurrentPage();
$this->controller->setArea($this->area);
?>
<div class="box">
<? if (($this->controller->subArea()->getTotalBlocksInArea($c) != 0) || ($c->isEditMode())) : ?>
<div class="box-header">
<?php $this->controller->subArea(); ?>
</div>
<? endif; ?>
<? if (($this->controller->subArea()->getTotalBlocksInArea($c) != 0) || ($c->isEditMode())) : ?>
<div class="box-footer">
<?php $this->controller->subArea(); ?>
</div>
<? endif; ?>
</div>
任何指向正确方向的指针都将不胜感激。
干杯
Ben
不确定"区域分割器"插件。。。我相信这是一个非常古老的东西,已经被核心中的原生"区域布局"所取代(我相信早在5.4中就添加了)。
如果你说的是原生的"区域布局"功能,那么我在免费的PageListTeasers插件中有一些代码可以做到这一点:
$aHandle = 'Main'; //<--CHANGE THIS ACCORDINGLY
$c = Page::getCurrentPage();
//Get blocks inside "Area Layouts"...
$layout_blocks = array();
$area = new Area($aHandle);
$layouts = $area->getAreaLayouts($c); //returns empty array if no layouts
foreach ($layouts as $layout) {
$maxCell = $layout->getMaxCellNumber();
for ($i=1; $i<=$maxCell; $i++) {
$cellAreaHandle = $layout->getCellAreaHandle($i);
$cellBlocks = $c->getBlocks($cellAreaHandle);
$layout_blocks = array_merge($layout_blocks, $cellBlocks);
}
}
//Get non-area-layout blocks...
$nonlayout_blocks = $c->getBlocks($aHandle); //Returns blocks in the order they're on the page
//Combine the two sets of blocks
$blocks = array_merge($layout_blocks, $nonlayout_blocks);
希望您可以使用该代码并对其进行修改,以实现您想要的内容(例如,根据您想要的,对layout_blocks数组或组合数组调用count()
)。