Drupal – Customize Block Template File

In the Drupal template architecture, you can customized a specific block just by creating a .tpl.php file in the theme folder. For example, the block.tpl.php determine all the block layout in your Drupal theme.

We can also override the design layout of the block in our customized module which we created yesterday(Drupal – Create a Block). First we have to create the corresponding .tpl.php for our block. In this case, we need a block-[module-name].tpl.php.

So create the block-custom.tpl.php

<strong>Hello World</strong>
<!-- get the block details from the $block variable -->
<p>Subject:<?php print $block->subject ?></p>
<p>Content:<?php print $block->content ?></p>


 

See what you get now.

 

You can find more information about the template naming convention at Theming blocks individually, by region, or by module.

If you are using a starter theme, please also copy the block.tpl.php from the parent theme folder to the starter theme folder.

Next suggested article: Drupal – Show Database Data in Block by SQL

Done =)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.