Place blocks and menus anywhere on the site

When you make a theme sometimes need to place a block directly into the theme instead of using the blocks section. For example, you need to insert the block in the page.tpl.php file what have to do is:

Print comments block:

<?php
$block = module_invoke('comment', 'block', 'view', 1);
print $block['subject'];
print $block['content'];
?>

Print locale block:

<?php
$block = module_invoke('locale', 'block', 'view', 0);
print $block['subject'];
print $block['content'];
?>

Print search block:

<?php
$block = module_invoke('search', 'block', 'view', 0);
print $block['subject'];
print $block['content'];
?>

Print custom block ("1" indicates first block):

<?php
$block = module_invoke('block', 'block', 'view', 1);
print $block['subject'];
print $block['content'];
?>

Print some menu block:

<?php
$block = module_invoke('menu', 'block', 'view', "some_menu");
print $block['subject'];
print $block['content'];
?>

0
Your rating: None

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: [code], [blockcode], [as], [as3], [css], [drupal5], [drupal6], [html], [java], [javascript], [mysql], [php], [xml].
  • You may quote other posts using [quote] tags.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.