James Crook, web geek ++

Add a block within a node.tpl.php file - Drupal 7

01 Aug 2011

To insert a block directly within any node.tpl.php file, or indeed within any page.tpl.php file, you can use module_invoke.

To find the right variables to pass go to the block page within Drupal admin and hover over the 'configure' links for each block. The path tells you the module and block id that make up the first and third variables. The second one should always be 'block_view' if you want to view the block (and we do).

Example: inserting a webform block

To insert a webform block directly into a node tpl, first make sure you've enabled a block from the advanced settings on the webform itself.

Then visit 'Structure' > 'Blocks' and look at the configuration link for the webform block in question.

If the configure link is admin/structure/block/manage/webform/client-block-44/configure then the code to place it will be:

$block = module_invoke('webform', 'block_view', 'client-block-44'); print render($block);

Categories: 

Comments

15 Apr 2012

Thanks for sharing...I just used it in one of my tpl files. Placed a menu block into the content area of a certain content type. Worked perfect.

03 Oct 2013

Essential blog post! I truly enjoyed reading it, as well as most of the posts on here. That is a truly good blog, thanks for taking the time to put it together. Thank you! <a href="http://goo.gl/r9iIT7">machine computer</a> <a href="http://goo.gl/M5Q3UD">Jual voltage stabilizer</a> <a href="http://goo.gl/64vQJT">Jasa SEO Murah Bukan Pakar SEO</a> <a href="http://goo.gl/tdh1iT">Jasa SEO dan Pakar SEO</a> <a href="http://goo.gl/nRifKz">Cara Murah</a> <a href="http://goo.gl/creCyl">distributor vinyl beli vinyl importir vinyl</a> <a href="http://goo.gl/BPgErc">Beli Wallpaper Toko Wallpaper</a> <a href="http://goo.gl/UUd49V">kayu lantai parket vinyl lantai</a> <a href="http://goo.gl/ui4h9d">Masakan Khas Indonesia Resep Masakan Resep Makanan Resep Minuman Masakan Ala Indonesia</a> <a href="http://goo.gl/TawMx2">RESEP PUDING BUAH</a> <a href="http://goo.gl/CVCS5X">Resep Dadar Gulung</a> <a href="http://goo.gl/UNlmEE">Resep Sayur Lodeh</a> <a href="http://goo.gl/JmifuW">Resep Tumis</a> <a href="http://goo.gl/t2b3GJ">Resep Telur Dadar</a> <a href="http://goo.gl/w07Lyy">Resep Tempe</a> <a href="http://goo.gl/RLjuwF">RESEP IKAN</a> <a href="http://goo.gl/Em6P3K">RESEP SAMBAL GORENG</a> <a href="http://goo.gl/ciBClC">Resep Kepiting Saus Padang Paling Enak</a> <a href="http://goo.gl/a2AkmL">Resep Sate Kambing Bumbu Kecap</a> <a href="http://goo.gl/8SxKaX">Resep Daging Sapi Lada Hitam Empuk</a> <a href="http://goo.gl/iO4pSI">Resep Sup Daging Lezat Gurih Enak</a> <a href="http://goo.gl/1Hs5HK">Resep Mie Ayam</a> <a href="http://goo.gl/JyqEtq">Tips Selama Kehamilan</a> <a href="http://goo.gl/d7R8qN">Tips Yoga Ibu Hamil</a> <a href="http://goo.gl/NYt0q5">Tips Sehat Hamil</a> <a href="http://goo.gl/6VXrfH">Tanda Kehamilan</a> <a href="http://goo.gl/l497LD">Buku Tips Hamil</a>

23 May 2012

I needed to print render($block['content']) to get it working properly, but thanks!

25 May 2012

Thanks for this (and to Harm Jan - I needed to add that too).

23 Dec 2012

I am Cipto Junaedy,
Hey great website! Does running a blog like this take a lot of work?
I have absolutely no expertise in computer programming but I
had been hoping to start my own blog soon. Anyhow, if you have any
suggestions or tips for new blog owners please share.
I know this is off topic but I just wanted to
ask. Thank you!

25 Dec 2012

Doesn't seem to work fine with my Webform.
I tried the above code and the block prints well in the node but when I'm hitting the submit button, it will not send any email. Webform doesn't even add it to the submissions list. When I use the Webform block the normal way, it just works as normal.

19 Aug 2013

Hey, I think your site might be having browser compatibility issues.
When I look at your website in Opera, it looks fine but when opening
in Internet Explorer, it has some overlapping. I just wanted to give
you a quick heads up! Other then that, excellent blog!

03 Jan 2013

Its Really good and helped me...THANKS

11 Feb 2013

Google Secret! Don’t pass this around please….

05 Apr 2013

altefalcope <a href="http://vikawieier.com">xaikalitag</a> Nupestemype http://uillumaror.com - iziananatt Gymnsypeshy http://gusannghor.com Icercefaree

12 Apr 2013

altefalcope <a href="http://vikawieier.com">xaikalitag</a> Nupestemype http://uillumaror.com - iziananatt Gymnsypeshy http://gusannghor.com Icercefaree

02 Jun 2013

altefalcope <a href=http://vikaswieier.com>xaikalitag</a> Nupestemype http://usillumaror.com - iziananatt Gymnsypeshy http://gussannghor.com Icercefaree

13 Oct 2013

Great post and a really good blog. Thank you so much for your efforts to put this amazing source of useful information together. Keep the great work up! http://www.machinecomputer.co.uk/ machine computer http://goo.gl/nQGoHr Taman Kenangan Lestari Lestari Memorial Park http://goo.gl/M5Q3UD stabilizer voltage http://goo.gl/64vQJT PAKAR SEO JASA http://goo.gl/tdh1iT Jasa SEO Pakar http://goo.gl/creCyl importir distributor vinyl beli http://goo.gl/BPgErc Beli Wallpaper Toko http://goo.gl/UUd49V parket kayu lantai vinyl http://goo.gl/0mQvSt Cara Sederhana Membuat Voltage Stabilizer http://goo.gl/RXTE5s Cara Murah Membuat Voltage Stabilizer Sederhana http://goo.gl/C9vugS cara membuat voltage stabilizer sederhana http://goo.gl/Yktpoa membuat voltage stabilizer sederhana http://tipsjitucaracepathamil.blogspot.com/ Tips Jitu Cara Cepat Hamil http://goo.gl/uxqdPA Lestari Memorial Park http://goo.gl/JZu4s3 Taman Kenangan Lestari Karawang http://goo.gl/75XXeI Lestari Memorial http://goo.gl/vmFKUK Lestari Memorial Park http://goo.gl/3Qtr6p Lestari Memorial Garden http://goo.gl/zrwU8k Pemakaman Taman Kenangan http://goo.gl/AJf1cc Pemakaman Lestari Memorial http://goo.gl/bxVtpy Pemakaman Taman Kenangan Lestari http://goo.gl/JyqEtq Tips Selama Kehamilan http://goo.gl/d7R8qN Tips Yoga Ibu Hamil http://goo.gl/NYt0q5 Tips Sehat Hamil http://goo.gl/6VXrfH Tanda Kehamilan

15 Apr 2014

Its just that sinmple:
<?php
print render($content['webform']);
?>

Add new comment