[SOLVED] How to Render a Block?

| | 1 min read

To render a block, a few methods are used. One way to render is to use block_load() function. In order to render a block, the following syntax is used,

if ($type == 'block') {
    $module = 'views';
    $bid = 'home_page-block_13';
    $block = block_load($module, $bid);
    $replacement = render(_block_get_renderable_array(_block_render_blocks(array($block)))); 

For block_load(), two parameters are passed. The first parameter is the module providing the block or the module used to create the block. The second parameter is the id of the block. This is how an edit url of the block appears. admin/structure/block/manage/views/home_page-block_13/configure

It is easy to identify the first and second parameters from the URL, just after 'manage' would be the module used to create the block, and next would be the block id.

To render the block, render function along with _block_get_renderable_array and _block_render_blocks. This will render the block to the node page. Happy coding.