In drupal 7, I want to render block into another block, for example block-1 into block-2. I guess I should put some PHP code into block-2, but I don't know what the code could be?

  • Putting "some PHP code into block" is a very bad idea. Please elaborate on what you want to accomplish, as this doesn't make sense without more context. – Letharion Apr 15 '12 at 8:40
  • Are looking to multiple, related pieces of content together like a mini-panel? (drupal.stackexchange.com/questions/28266) – Ashlar Apr 15 '12 at 14:54
  • 1
    like <?php print render(block_load($module, $delta)); ?>? – artfulrobot Apr 15 '12 at 19:56
  • @Letharion, "newsletter" module created "newsletter" block which I want to put that into some reserved place in other block – Sadegh Apr 16 '12 at 8:00
  • @Ashlar, Thanks for your response, I don't know what mini panel is, but I'm trying to figure that out :) – Sadegh Apr 16 '12 at 8:05

Based on Ashlars's comment.

A minipanel, provided by Panels, is for anyone not used to Panels, essentially a block, that supports internal layouts. You can use a mini-panel to wrap several different blocks (and many other things, views, nodes, etc) into a single "block".

Unfortunately, I must admit that documentation is scarce on this topic. I will refer you to this other question: looking for a good mini panels tutorial.


Completely agree with Letharion's comment but if there is absolute need for such, this code snippet can help:

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

If you are unsure what are exact parameters for 'module_name' and 'block_delta' I'd recommend searching the database table block and locating your specific

  • module_name under column module
  • block_delta under column delta

second parameter block_view remains exactly like that.

Reference: https://www.drupal.org/node/26502

  • Good solution, however, it might not a best practice, especially if the client has write access to the block (which they probably would, because that's what a CMS is for). The client breaks any PHP code, and the entire site goes down. – dayuloli Feb 26 '15 at 5:01
  • Beyond that issue, this sometimes is the sharpest way to go. To invoke a block, you'd use this code, for example: <?php $block = module_invoke('block', 'block_view', BLOCK_ID_PASTE_HERE); – Meetai.com Apr 16 '15 at 3:14
  • It was good to point out that find out the 'module_name' and 'block_delta' by searching DB, useful trick! – hailong May 11 '18 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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