I know how to print a block in a node but how do I add a "menu block" in a node? I'm hoping this is something easy that I am just overlooking so any help is appreciated.
<?php
$block = module_invoke('block', 'block', 'view', 1);
print $block['content'];
?>
I tried modifying the code that allows you to print blocks in nodes with no luck.
Thanks!
Comments
Comment#1
Buddharide commentedHere's how to do it in Drupal 6. Simply change the "1" to the number of the block.
<?php
//下在的代码绝对有大用
$block = module_invoke('menu_block', 'block', 'view', '1');
print $block['content'];
?>
Namaste.
Adam Hegi
primalmedia.com
Comment#2
ice5nake commentedThat method doesn't display the title for me.
Comment#3
bstoppel commentedHave you tried printing $block['title']?
Comment#4
datawench commentedEven more straightforward, without using a separate module:
<?php
$block = module_invoke('menu', 'block', 'view', 'menu-your-menu-name');
print $block['content'];
?>
Comment#5
doublejosh commentedhttp://drupal.org/node/164799
Comment#6
jamesrutherford commentedIn Drupal 7 hook_block has changed to hook_block_op, so in order to make the above(comment #1 and #4) work you need to make some simple changes, namely changing ('block', 'op') to 'block_op'.
Example:
$block = module_invoke('menu', 'block_view', 'menu-my-menu-name');
print render($block['content']);
This will work similarly to what worked in Drupal 6, as demonstrated in comment #4 above.
Comment#7
Lasac commented@james:
<?php $block = module_invoke('menu', 'block_view', 'menu-main-menu'); ?>
Doesnt do it for me, where do i find the menu name????? Why isnt that the block id?Comment#8
Lasac commentedDoesn't do it either:
<?php $block = module_invoke('menu_block', 'block_view', 1); ?>
Just prints Array.
Comment#9
Lasac commentedOff course:
print render($block['content']);
.For others:
<?php $block = module_invoke('menu_block', 'block_view', 1); ?>
<?php print render($block['content']); ?>
Comment#10
alphex commentedNo solution to this yet?
Trying the options above give an array... or prints the wrong menu.
menu-block module doesn't provide an ID number in the block admin screen.
Comment#11
Lasac commentedit does in the url/path
Comment#12
Peacog commented@ice5nake: You can get the title with
<?php print $block['subject']; ?>
Comment#13
upunkt commented@lasac This does also work in Drupal 7:
Retrieve the number from Admin/Structure/Blocks and hovering over the "configure" link. The number is in this link after ...manage/menu_block/
Comment#14
TelFiRE commentedWhy so many different answers, none of which work?! It's a simple and straightforward question yet completely undocumented.
block_render is an undefined function, no idea why that would be working for you.
Really like this module but what is the actual, official way of embedding a block in PHP? None of the solutions here work for me.
Comment#15
hansrossel commentedI can confirm that #9 works
Comment#16
simone960 commentedI have tested in D7, here the codes work for me :)
To embed menu block:
<?php
$block = module_invoke('menu_block', 'block_view', 3);
print render($block['content']);
?>
To embed original "Main menu" (NOT "menu-main-menu"):
<?php
$block = module_invoke('menu', 'block_view', 'main-menu');
print render($block['content']);
?>
To embed other menu beside main menu as #6 @jamesrutherford pointed out.
<?php
$block = module_invoke('menu', 'block', 'view', 'menu-your-menu-name');
print $block['content'];
?>
e.g, 'menu-product'
Comment#17
mareks commentedAny ideas if/or how does the module_invoke work with the i18n menu blocks?
Thanks,
来自 https://www.drupal.org/node/505712