Drupal 7 – Render a Block programmatically

Not long a ago, i have 2 posted about rendering Blocks and Views in PHP.

We can render the Drupal 7 block by PHP in another way.

1. Find out the block which you want to render from the db table called block.

2. You could see there are 2 columns, one is called module and the other is called delta. These 2 data are what we need to render the block programmatically.

3. Use the following piece of code to print the block in PHP.

  $block = block_load(<module>, <delta>);
  print render(_block_get_renderable_array( _block_render_blocks(array($block))));


The above method works even for block created by Views.

Done =)



3 thoughts on “Drupal 7 – Render a Block programmatically”

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 )

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.