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

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:

  1. Open /config/site_post.php in your preferred code editor.
  2. Define the handle of the block to load:
    $handle = 'hello_world';
  3. Load the block by its handle:
    $block = BlockType::getByHandle($handle);
  4. 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.

主站蜘蛛池模板: 陵川县| 沾益县| 永清县| 鹤山市| 大足县| 都兰县| 广河县| 湟源县| 隆昌县| 曲水县| 佛学| 乌鲁木齐市| 崇阳县| 色达县| 库伦旗| 甘肃省| 韶山市| 安溪县| 喀喇沁旗| 任丘市| 台中市| 辉县市| 满城县| 九龙县| 金溪县| 贡嘎县| 遂川县| 仙桃市| 田林县| 永德县| 台山市| 蒙山县| 吴旗县| 华亭县| 鄂尔多斯市| 遂昌县| 木里| 金秀| 昌平区| 视频| 南投县|