Print a block in a contemplate

big_smile - June 8, 2009 - 12:01
Project:Content Templates (Contemplate)
Version:6.x-1.1
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Is it possible to print a contemplate in a block?

I know it wasn't possible in the 5.0 versions of contemplate, but I am wondering if things might have changed?

#1

jrglasgow - June 8, 2009 - 14:02

Your title and the content of the post are opposite meaings.

Do you want instruction on printing the contents of a block in a template.

or instructions on how to print the results of a template in a block?

#2

big_smile - June 9, 2009 - 16:07

Sorry - I want to know how to print a block inside a contemplate.

Sorry for this mix up!

#3

tyler-durden - November 10, 2009 - 03:35

I found this post by searching the exact title - I am looking to find a way to add blocks to a Content Template also. My guess is that this is not possible, correct?

#4

jrglasgow - November 13, 2009 - 16:25

Yes it is possible to print a block in a content template.

First you need to know the module that provides the block, then you need to know which block it is according to that module. Then you invoke the hook_block of that module.

<?php
   $content
= module_invoke([module], 'block', 'view', $delta);
   print
'<h2 class="title">'. $content['subject'] .'</h2><div class="content">'. $content['content'] .'</div>';
?>

Take for instance the Search Form block provided by the search module. Here is the path to configure the block from the /admin/build/block page:
/admin/build/block/configure/search/0

From this path I know that the module is 'search' and the $delta is '0'. I would write my code like this:
<?php
   $content
= module_invoke('search', 'block', 'view', 0);
   print
'<h2 class="title">'. $content['subject'] .'</h2><div class="content">'. $content['content'] .'</div>';
?>

This works great for most blocks, but if the block you want to embed is a view I suggest views_embed_view().

 
 

Drupal is a registered trademark of Dries Buytaert.