- concrete5 Cookbook
- David Strack
- 195字
- 2021-08-13 16:16:02
Loading a block type by its handle
Block types are objects in concrete5 just like most things. This means that they have IDs in the database, as well as human-readable handles. In this recipe, we will load the instance of the block type that we created in the first recipe of this chapter.
Getting ready
We will need a place to run some arbitrary code. We will rely on /config/site_post.php
once again to execute some random code. This recipe also assumes that a block with a handle of hello_world
exists in your concrete5 site. Feel free to adjust that handle as needed.
How to do it...
The steps for loading a block type by its handle are as follows:
- Open
/config/site_post.php
in your preferred code editor. - Define the handle of the block to load:
$handle = 'hello_world';
- Load the block by its handle:
$block = BlockType::getByHandle($handle);
- Dump the contents of the block to make sure it loaded correctly:
print_r($block); exit;
How it works...
concrete5 will simply query the database for you when a handle is provided. It will then return a BlockType
object that contains several methods and properties that can be useful in development.
- Mastering Concurrency Programming with Java 8
- AngularJS入門與進階
- UML和模式應用(原書第3版)
- 數據結構簡明教程(第2版)微課版
- 64位匯編語言的編程藝術
- Java Web應用開發技術與案例教程(第2版)
- Python數據分析從0到1
- 小學生C++創意編程(視頻教學版)
- JavaCAPS基礎、應用與案例
- Mastering Xamarin.Forms(Second Edition)
- Access 2010中文版項目教程
- 用案例學Java Web整合開發
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- Angular應用程序開發指南
- Python趣味編程與精彩實例