- 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.
- 深入核心的敏捷開發:ThoughtWorks五大關鍵實踐
- Spring 5.0 Microservices(Second Edition)
- Delphi程序設計基礎:教程、實驗、習題
- Java高并發核心編程(卷2):多線程、鎖、JMM、JUC、高并發設計模式
- Getting Started with ResearchKit
- C語言程序設計實訓教程
- Animate CC二維動畫設計與制作(微課版)
- Python進階編程:編寫更高效、優雅的Python代碼
- Java EE 8 Application Development
- Terraform:多云、混合云環境下實現基礎設施即代碼(第2版)
- JavaScript程序設計(第2版)
- Visual Basic程序設計習題與上機實踐
- 零基礎學Python編程(少兒趣味版)
- Zabbix Performance Tuning
- Mastering Apache Camel