Share icon

This is article is for Drupal 7 to render block in templates and custom blocks using php codes

Actually there is very simple ways to render block pro-grammatically 

1) Module Invoke

$block = module_invoke('module_name', 'block_view', 'delta or machine name of block');
print render($block['content']);

Module invoke is most common way to render a block, above example is self explained or see the below example

$block = module_invoke('search', 'block_view', 'search');
print render($block);

2) Using Block Load with delta

$block = block_load('block', '1');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;

3) Using Block load with Name

$blockObject = block_load('views', 'block_name');
$block = _block_get_renderable_array(_block_render_blocks(array($blockObject)));
$output = drupal_render($block); print $output;

4) Render Views Block

echo views_embed_view('view_machine_name', 'block_1');

5) Render Views Block with Arguments of contextual filters

echo views_embed_view('view_machine_name', 'block_1','arg1','arg2');

Comment for any other help thanks

Please Comment your thoughts and feedback below and add something if you found good in anywhere to help others

Hit a like Button If you like the Post.

Many Thanks


Profile picture for user Ronak Kumawat
Jordan (not verified)
08 Jun 2022
That very good explained, thanks

Add new comment

Restricted HTML