I'm a novice drupal coder and trying to accomplish the following

My scenario is such that i have the template files block-mymod-1.tpl and block-mymod-2.tpl respectively.

What i'm intending to do is get the data of block 2 to be displayed in that of 1.

currently $block->subject and $block->content in block-mymod-1.tpl give the subject and content of block1.

Is there a drupal way of overload the $block so that it could hold the subject and content of second block also?

Apparently my google skills were not good enough or i couldn't find a direct answer.

Any positive response would be greatly appreciated..

Thanks n Cheers!!!

  • Is the second block a literal carbon copy of the first block? Or is the content in the first block just a portion of what will be in the second block? – Chapabu Nov 21 '11 at 11:49
  • @Chapabu no they are not copies of each other.. let's say they are similar but certainly not identical.. – optimusprime619 Nov 21 '11 at 13:34

I'm not 100% sure if this will work, but it's worth a try!

You may be able to use module_invoke to place block 2's content into the template of block one using the following code in your block-mymod-1.tpl:

$block = module_invoke('block', 'block', 'view', '2');
print $block['content']

This post might help to explain more, but for your needs you are only interested in the first and last arguments. The first tells Drupal which module you're invoking, and the last is the block ID of the node you're looking to load the data for.

  • thanks for the link will try it out and let you know in a while... – optimusprime619 Nov 22 '11 at 9:51
  • worked like a charm.... you sir are an artist.... simple and elegant solution ...drupal is the best... – optimusprime619 Nov 22 '11 at 17:45

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.