是否可以检查subArea是否包含Concrete5中的块?

时间:2014-04-23 03:39:44

标签: php concrete5

使用Area Splitter插件时,有没有办法在输出标记之前检查subArea是否包含块?

一直在尝试这样的东西,但不明白如何使它工作抱歉:

<?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>

非常感谢任何正确方向的指示。

干杯

1 个答案:

答案 0 :(得分:0)

不确定“区域分割器”插件......我认为这是一个非常古老的东西,已经被核心中的原生“区域布局”所取代(我相信它已经回到了5.4中)。

如果您正在谈论本机“区域布局”功能,那么我在免费Page List Teasers addon中有一些代码可以执行此操作:

$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(),具体取决于您想要的内容。)