1
votes

this is a question how to override themable items in Drupal 6.

According to the book "Pro Drupal Development", we can override themable items in two ways:

  1. overriding via Theme functions
  2. overriding via Template files

So for example, in order to reformat the breadcrumb, I can:

  1. via function theme_breadcrumb($breadcrumb)
  2. via breadcrumb.tpl.php

But on my local testing server, the second approach (i.e. via template file) is not working! I see no breadcrumbs at all, while the first approach works fine.

Any idea how could this happen? any special settings I need to configure my Drupal?

thanks!

My custom theme "greyscale":
sites\all\themes\custom\greyscale:
- breadcrumb.tpl.php
- greyscale.info
- node.tpl.php
- page.tpl.php
- style.css
- template.php

relevant file contents:
* template.php:

function phptemplate_preprocess_breadcrumb(&$variables) {
  $variables['breadcrumb_delimiter'] = '#';
}
  • breadcrumb.tpl.php:

alt text

2
Are you other template files working as expected?Jeremy French
Maybe I phrased my question not so well. My real question was: I had a template file "breadcrumb.tpl.php" there, but Drupal was not aware of that, although I clicked multiple times "Administer -> Site building -> Modules" (according to "Pro Drupal Dev" this would refresh the theme registry, which is not the case.Jin Hui
I figured out the problem: I change the theme to another one and then switch back to my custom theme, now Drupal sees my "breadcrumb.tpl.php". Seems like this is the correct way to refresh the theme registry.Jin Hui

2 Answers

4
votes

Theme functions are setup to either use a template or a function to generate the markup, it will never use both as that's pointless.

For a theme function to use a template, it must be defined when you define it in hook_theme.

A template + preprocess function and a theme function really does the same thing: produce markup. It depends on the situation which method is best to use, that's why we have two. The good thing about templates, is that it allows themers to change the markup, without know much about PHP or Drupal.

Cache

Drupal caches all templates and theme functions defined in your theme, when you create new ones, you need to clear the cache, this can be done by:

  • Use drush
  • Clearing cache in admin/settings/performance
  • Use devel to clear it on each page load. Usable during development, biut will kill performance.

Switching theme back and forth will work too, but it really not the desired way to do it.

0
votes

I personally always find it easier to alter breadcrumbs through template.php using hook_breadcrumb()

function mytheme_breadcrumb($breadcrumb) {
  $sep = ' > ';
  if (count($breadcrumb) > 0) {
    return implode($breadcrumb, $sep) . $sep;
  }
  else {
    return t("Home");
  }
}

Any particular reason why you wish to use a .tpl.php file?