官术网_书友最值得收藏!

Getting the blocks from an area

concrete5 pages can have several different areas where blocks can be added. Developers can programmatically get an array of all of the block objects in an area. In this recipe, we will load a page and get a list of all of the blocks in its main content area.

Getting ready

We will be using /config/site_post.php to run some arbitrary code here. You can place this code wherever you find appropriate, though.

This example assumes the presence of a page with a path of /about, and with a content area called content. Make the necessary adjustments in the code as needed.

How to do it...

The steps for getting the blocks from an area are as follows:

  1. Open /config/site_post.php in your code editor.
  2. Load the page by its path:
    $page = Page::getByPath('/about');
  3. Get the array of blocks in the page's content area.
    $blocks = $page->getBlocks('content');
  4. Loop through the array, printing each block's handle.
    foreach ($blocks as $block) {
      echo $block->getBlockTypeHandle().'<br />';
    }
  5. Exit the process.
    exit;

How it works...

concrete5 will return an array of block objects for every block that is contained within a content area. Developers can then loop through this array to manipulate or read the block objects.

主站蜘蛛池模板: 千阳县| 青冈县| 家居| 礼泉县| 安多县| 开平市| 腾冲县| 佛教| 怀来县| 德清县| 团风县| 西充县| 兰坪| 辛集市| 卫辉市| 囊谦县| 皮山县| 棋牌| 林周县| 临湘市| 平潭县| 景东| 阿勒泰市| 安岳县| 剑阁县| 友谊县| 陈巴尔虎旗| 临沧市| 定西市| 寻乌县| 黄骅市| 新龙县| 灵丘县| 三都| 桂林市| 周宁县| 饶平县| 保定市| 梁河县| 宁海县| 宣汉县|