Drupal – Render a Block in PHP Code

You can render a block in PHP as follow.

...
$block = (object) module_invoke('<module>', 'block', 'view', "<block id>");
print theme('block', $block);
...


 

If your block is a create by Views, then the <module> is views. For other normal blocks, just simply use block. And you can find out the <block id> @ Adminster -> Site building -> Blocks as depicted below.

 

Move your mouse to the configure link and you can find the block id. In the above picture, the block id is latest_search-block_1.

Done =)

Reference: Drupal Docs – Placing the contents of a block in any location

2 thoughts on “Drupal – Render a Block in PHP Code”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.