Hello i am trying to avoid using the block system with drupal. Im using panels and i dont like having to add the main content if i use any block in a region. anyhow.... i was hoping to add a menu block i have to my page.tpl

The block i want to add has this url to it when i edit it- block/manage/menu_block/2/configure

The code im using to add another block is

      $block = module_invoke('md_megamenu', 'block_view', '1');
      print $block['content'];

Ive tried a few things with not much success. If i was to choose my best effort it would be-

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

this just shows 'array' though.

could anyone suggest anything i should try?



It seems like you're mixing the Drupal 6 and Drupal 7 api a little bit.

If you're on Drupal 7, you should print out your block like this:

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

Note the 'print render'. (You're missing the 'render' part if you're on Drupal 7.

The only things you need to change are to put 'menu_block' for the 'module_name' and your block's machine name for 'block_delta'.

More info and examples are on drupal.org: http://drupal.org/node/26502

Does that work for you?

============ Edit ==============

On the other hand, if you're on Drupal 6, your call should look something like this:

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

In this case, you're fine with the just 'print $block['content']', but your arguments are a little off. From what you're saying though, it sounds like you're on Drupal 7, and are just returning the array without rendering it!!! :-)

| improve this answer | |
  • ah thanks Boriana i was away off working on another of my drupal problems there. Let me read up....ah wait a sec...before i do this ive just realised that ive resorted to using a sidebar in my theme and im just putting the blocks in there. That said my md_megamenu block will need the D7 way of doing things you suggest. Let me go try that....yip thats great Boriana. Im glad i found out that im doing things the wrong way. Much appreciated thanks – Reg Gordon Apr 24 '13 at 20:14

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.