- concrete5 Cookbook
- David Strack
- 206字
- 2021-08-13 16:16:02
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:
- Open
/config/site_post.php
in your code editor. - Load the page by its path:
$page = Page::getByPath('/about');
- Get the array of blocks in the page's content area.
$blocks = $page->getBlocks('content');
- Loop through the array, printing each block's handle.
foreach ($blocks as $block) { echo $block->getBlockTypeHandle().'<br />'; }
- 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.
- Practical Data Analysis Cookbook
- 計算思維與算法入門
- Photoshop智能手機APP UI設計之道
- Getting Started with ResearchKit
- 深入實踐Spring Boot
- Learning Bayesian Models with R
- MATLAB應用與實驗教程
- Visual C++應用開發(fā)
- 高級語言程序設計(C語言版):基于計算思維能力培養(yǎng)
- Spring Boot企業(yè)級項目開發(fā)實戰(zhàn)
- Working with Odoo
- Canvas Cookbook
- Raspberry Pi Robotic Blueprints
- Elastix Unified Communications Server Cookbook
- MATLAB計算機視覺實戰(zhàn)