Tag Archives: Drupal Theme

Drupal – Theme node template by module

Suppose we have a content type called Silly Question. We can theme the node template by adding the node-silly_question.tpl.php in the theme folder. But if we are working on a module, we should ask Drupal to read the .tpl.php in our module folder first because we shouldn’t ask the module user to copy the .tpl.php from our module folder to their theme folder.
Continue reading Drupal – Theme node template by module

Drupal – Introduction to Drupal Theming @ 3

Update @ 20130303: For Drupal 7, please refer to the following post.
Drupal 7 – Create your own theme function on your custom block

 

Previous related articles
Drupal – Introduction to Drupal Theming @ 1
Drupal – Introduction to Drupal Theming @ 2

So we could now use a .tpl.php for our customized content. The last thing i would like to mention is about the preprocess function.

Suppose i want to load a node content on the .tpl.php, we can either include the node as an arguments when calling the theme function like. Continue reading Drupal – Introduction to Drupal Theming @ 3

Drupal – Introduction to Drupal Theming @ 2

Yesterday we have talked about the simplest way to theme Drupal content
Drupal – Introduction to Drupal Theming @ 1

But this is not a very good approach because printing inline HTML/PHP inside the theme function is not a good programming practice. This time, i want to create a .tpl.php for the block so we could separate the backend and frontend coding.

Create the following module. Continue reading Drupal – Introduction to Drupal Theming @ 2

Drupal – Add Image to Apache Solr Search Result

Apache Solr is a very good web search engine and it works very well with Drupal. This post shows you how to customize the default pure text search result template by adding node image to each result record.

First, we need to load the corresponding node for each search result. This can be done in the <theme>_preprocess_search_result(&$variables) function. Add it to the template.php. Continue reading Drupal – Add Image to Apache Solr Search Result

Drupal – Add Previous and Next Links for Node Navigation

When you are viewing a node, it would be nice to have the previous and next navigation buttons so that you can browse other nodes of the same content type more easily. This is exactly the recent task i need to complete. Luckily i found a very good post showing how to add the navigation buttons in just 2 steps.

1. Add the following function in your theme template.php Continue reading Drupal – Add Previous and Next Links for Node Navigation

Drupal – Add page.tpl.php for different Content Type

In Drupal, we can determine the template files of the page which is going to be rendered. Add the following code in your template.php.

...
function <theme>_preprocess_page(&$vars) {
  // Drupal 7
  print_r($vars['theme_hook_suggestions']); exit();

  // Drupal 6
  print_r($vars['template_files']); exit();
}
...

  Continue reading Drupal – Add page.tpl.php for different Content Type