In Drupal 6, it was easy to insert a block into a template with the following code:
$block = module_invoke('views', 'block', 'view', 'block_name');
print $block['content'];
However, using the same instructions in Drupal 7 does not seem to work. I have looked around and cannot find the new method.
Does Drupal 7 have a routine that can allow for programmatically inserting a block into a template or node?
In my search to include a block in a template, i came across this post.
As an addition, if you want to include a custom block (that you added through the block interface) you have to use (instead of
block_load();
in drupal 7)This work for me:
98 is the id of the block
The
module_invoke()
function works. However, I found that rendering a block this way apparently won't use a custom template for that block. This might be OK depending upon your needs.As commented before in other answers, this works as well and also makes use of custom templates:
So, if you have a custom
block--your-module--delta.tpl.php
template file, it will be used to format the block.Source: http://api.drupal.org/api/drupal/includes!module.inc/function/module_invoke/7
module_invoke Working fine for render block in the template file, but it's not working multilingual sites.
There's module called insert_block for those which want to insert block "Drupal way" (not to program anything, just enable the module). Here's how to set it up.
NOTE: I know this question is about "programmatically inserting a block into a template or node" but Google sends people here even their are looking for non-programmer solution like me.
For some reason
render()
doesn't work for me, but this does: