This feels like it should be SO simple, but I've been Googling and looking through the Drupal developer snippets for a few hours now and haven't seen anything about this.

How can I print a block in a page with D6??

I've defined a block with Views2 to show all my news item teasers and titles. I'm designing a custom page-front.tpl.php instead of using Panels (of course) and want to print it inside it. I would assume it's as simple as "print $block_name" or "print block('news')" but I can't find anything on it!

Thanks so much!

Comments

add1sun’s picture

Is there a particular reason you don't want to just use a region for this? Typically to put blocks in the page*.tpl.php you would just add a region to the theme, put the block in the region and then print $regionname in the tpl.

If you really want to hard-code for some reason, you can use http://api.drupal.org/api/function/theme_blocks/6. But really that is only done when you want to print blocks in a non-page tpl file.

Lullabot loves you
Our O'Reilly book is out! Using Drupal

Drupalize.Me, The best Drupal training, available all the time, anywhere!

dru_india’s picture

You can create a region in info(for D6) file of theme and print the name of region in between the html where you want to show the block ie:
print $header_bottom; in page-front.tpl.php
now enable your block in this region
I guess you know how to create a region in D6
OR

$block = module_invoke('block', 'block', 'view', "25(number of block)");

print $block['subject'];

print $block['content'];

Number of block-To get Number of block enable it to any region and you get the no end the end of url

japanitrat’s picture

you can also print it via the system theme function, all you have to do is converting it to object before:

<?php
$block = (object) module_invoke('[target_module]', 'block', 'view', "[target_block_ID]");
print theme('block',$block);
?>

where [target_module] is the module, which has the wanted block .. for instance, blocks that you have created via "add block", have as module "block" ... but blocks that you have created with the quicktabs module have "quicktabs" as module.
don't think about it that much, just go to you blocks admin-overview, click edit on the block you like and look for the last two items in the URL. For instance, lets say you want to have the primary-links block somewhere else: get to the blocks overview and locate "Primary links". Click on "configure", the default URL will be: admin/build/block/configure/menu/primary-links
in this case, your [target_module] would be "menu" and the [target_block_ID] would be "primary-links" ...

beware, some things are missing, because 'view' only gives you subject and content, whereas the theme function also looks for 'module' and such stuff .. check your block.tpl.php for additional variables that you may have to include in your $block object.

andrewsuth’s picture

@japanitrat: Thanks for your insight into this topic, I was lost as how to do this. I also found some documentation here

Quicktabs does not include a block.tpl.php file as part of the module so I am a little lost when trying to make it look like the real deal.

Can you give an example of the additional variables that might need to be included and where to find them?

msathesh’s picture

To print the webform block (in webform6.x.3.9 drupal 6.x), in a page such as page.tpl.php or any other template files, do the following

$block = module_invoke('webform', 'block', 'view', 'client-block-148');
print $block['content'];

replace the '148' in 'client-block-148' with yours.

eyurdakul’s picture

regions don't work as documented. i've ended up also just printing the blocks. i use page theme and there is a die in template_regions function, but it never gets fired. Now, it just doesn't print any shit in the region.

jlpz’s picture

These ways are all fine and i really use it a lot but i still havent found a way to print the block with all the benefits that you get when you print the block inside a region, one of the biggest one for me is the contextual links, if anyone know how to do this properly, printing a block in a template getting the contextual links to work please i would like to see it. Thanks!!