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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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