I would like to display blocks in region by code, in the same way that I can use context (so: if I'm on a node_view of type "article" display block "user login" on region "Sidebar first", for example).

I know how to load and display blocks but I don't know which is the best place to make it.

Have I to add the render function in regions template? Or have I to use a theme function to do this?

  • Why don't you just assign the block to a region, with visibility settings, in Admin > Structure > Blocks ? Jan 14, 2013 at 8:49
  • I know this, but I'm searching a way to do this by code
    – arrubiu
    Jan 14, 2013 at 9:48

1 Answer 1


Instead of using the admin blocks interface, if you really want to manually render blocks, you can render:

Directly in a template:

if ($block = module_invoke('module_name', 'block_view', 'block_delta')) {
  print render($block['content']); 

Via code, with drupal_add_region_content

if ($block = module_invoke('module_name', 'block_view', 'block_delta')) {
  drupal_add_region_content('left',  $block['content']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.