Drupal has a very advanced theming system. Everything that Drupal shows on the screen can be modified. Everything, are you sure? YES EVERYTHING!
The problem is that you need to find the right theme function to be able to do this. Sometimes when some output is not generated by a theme function, it's possible to use alternative measures but the amount of cases where you need to do this is quite low.
In this chapter I will discuss some basic best practices how you can find information about how to find the right hooks to theme certain aspects of Drupal.
The first place to look is the Drupal Theming Guide: http://drupal.org/theme-guide and more specifically... the Theme Snippets: http://drupal.org/node/45471. Don't just use the advice given in the article, also look in the comments for alternatives. Sometimes the comments contain better methods to theme certain aspects.
The second place to look is http://api.drupal.org. If I'm looking to theme the breadcrumbs then I just type in the textfield on the left the word breadcrumb and I instantly get an auto complete advice that tells me that the function: theme_breadcrumb($breadcrumb) exists. By navigating to this function I see the following code snippet:
function theme_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return ''. implode(' ยป ', $breadcrumb) .'';
}
}
By placing this snippet in the template.php file and changing theme to phptemplate I can immediately change the breadcrumb theming.
When you are not able to find the right function to theme a certain aspect, for example when I want to theme the primary links, then I use the good old Google search engine. So this search query: http://www.google.com/search?client=opera&rls=nl&q=primary+links+theming... leads to this page:
http://drupal.org/node/137788 telling me that I should override the theme_menu_links function.
In the extraordinary situation where nobody ever has asked the question you have then there still is one solution. Take the id or class of the html tag wrapped around the element that you want to theme and do a text search in all your Drupal files. Most probably you will find the file back that themes your element and by looking at the code you most probably will find a way how to theme the element. BUT NEVER, YES NEVER!!!! change the code of a Drupal core file. For a Muslim it's considered unholy to eat pork, for a Drupalist it's unholy to modify core!
I will finish with some good links to handbook articles for things that you might find interesting to theme:
- http://drupal.org/node/101092, theming CCK input forms
- http://drupal.org/node/128741, theming views
- http://drupal.org/node/154242, theming the Drupal registration form
- http://drupal.org/node/154113, theming the login/registration/request password full page
- http://drupal.org/node/19855, theming the login block






Post new comment