Drupal - Use Different Block Theme

Q: How can I apply a theme to some blocks on my drupal website that is different to the default block theme?

A: One way to do this is to use the most excellent Block Theme module and provide your own custom blocktheme-theme_name.tpl.php template file.

You may sometimes find that the block template provided by your website's theme is not suitable for all of your site's blocks. I am currently working on a site where the website design calls for a heavily themed block layout - while this is fine for most blocks I found that in some cases I wanted a block's content to be inserted in a raw form without any of the many styled divs that were wrapped around its content by the site's theme.

This is where the Block Theme module can help. It allows you to declare and use multiple alternative block templates. If you don't want a block to use the default template you can just associate it with on of your new custom templates instead....

There is a good tutorial on using the Block Theme module here:

http://mustardseedmedia.com/podcast/episode13

But to summarise the steps that I used to create and use a nice plain block theme -->

(a) Install the Block Theme module.

(b) Goto the Administer / Block Theme (admin/settings/blocktheme) settings page and add a new custom template, I called mine: plainblock|Plain Block

(c) Now go to your theme's folder and make a copy of block.tpl.php, name it blocktheme-custom_theme_name.tpl.php. As I had called my custom theme plainblock, I renamed it to blocktheme-plainblock.tpl.php

(d) Edit your new .tpl.php file and modify the template as required. I wanted to have my block content to be inserted with as little decoration as possible so I changed the template code to the following:

<div class="<?php print "block block-$block->module plain-block" ?>" id="<?php print "block-$block->module-$block->delta"; ?>">
<?php print $block->content ?>
</div>

(e) All you have to do to get a block to use your new custom template is to go to the block's configuration page and choose your custom template from the new 'Custom Theme' setting (and save!)

Now when your block is displayed it should be rendered with your new template, while all of your other blocks will be rendered with the default template!

Heavily Styled Block

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>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
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.

Proud member of the:
Irish Internet Association

phone-number.png