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

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.

主站蜘蛛池模板: 河间市| 临泉县| 东乡族自治县| 伊金霍洛旗| 温泉县| 昌黎县| 金秀| 丰原市| 邵阳市| 滕州市| 鹤峰县| 怀远县| 沧州市| 威信县| 贵南县| 重庆市| 阜阳市| 沐川县| 呼伦贝尔市| 遵义县| 安平县| 嵊州市| 兴文县| 福建省| 当雄县| 阜宁县| 广元市| 营山县| 自贡市| 潼关县| 石楼县| 永安市| 溧阳市| 东港市| 乌审旗| 五河县| 高邮市| 凉城县| 含山县| 井陉县| 和林格尔县|