tags:

views:

42

answers:

2

Hi there,

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

A: 

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?

wiifm
not really. I'm just wondering why Drupal can't see my template file "breadcrumb.tpl.php". I know that there're multiple ways to change the breadcrumb. thank you.
Jin Hui
+2  A: 

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.

googletorp
thanks, see my comments above. in short: I need to change switch to the theme in order for Drupal to refresh its theme registry.
Jin Hui