I've got a Garland-based theme, which works fine under Drupal 5.x, but I can't figure out how to get it to work under Drupal 6.x. When I say Garland-based, I took a copy of the files into a new sub-directory and modified node.tpl.php and template.php. The purpose was simply to allow me to format taxonomy terms differently.

I created a new function theme_terms(), added it to template.php and modified node.tpl.php to call it.

I changed node.tpl.php thus:

<?php if ($taxonomy): ?>
      on <?php print theme('terms', taxonomy_link('taxonomy terms', $node)) ?>
<?php endif; ?>

The function signature in template.php is:

function theme_terms($terms, $attributes = array('class' => 'terms')) {
  $output = '';
...
}

After upgrading my site to Drupal 6.x, I've got everything working except my mods to the Garland theme. I started with the D6 version of Garland, copied it and made the same changes as I did for D5, but no joy. I've read the upgrading guide and other D6 theme material. I've installed devel to assist, but no luck.

Can anyone explain what I need to do?

Comments

gpk’s picture

If I am not mistaken you are implementing a new theme function. In D5 this was all detected on-the-fly; in D6 you need to regsiter the theme function. Start here: http://drupal.org/node/173880#theme-registry.

Also you might want to create your new theme as a simple sub-theme, you'd probably only need the .info file, template.php and node.tpl.php which could all live happily under sites/all/themes...

A further improvement would be to implement mytheme_preprocess_node in your template.php to override $terms, thereby removing the theme call from node.tpl.php. You might not even then need the custom theme function. Here is how the default node preprocessor does it: http://api.drupal.org/api/function/template_preprocess_node/6.

dshaw’s picture

Hi gpk,

Thanks for all the tips. You are correct that it's a new function. However, I've read the link you gave and I can't figure out how I'm supposed to inform the registry of the new function? Can you be more specific?

I had already been playing around with a sub-theme. As you surmised, far fewer files. But I couldn't get the color to work initially. You're probably familiar with Garland's use of the color picker. Unless I had a color sub-directory (and the corresponding images dir and the style sheet) in the sub-theme sub-dir the color stuff didn't work. Everything else did.

I'll look into the pre-processe node idea. That looks clever.

gpk’s picture

To register your new theme function you would need to implement mytheme_theme() (i.e. hook_theme) within your template.php.

Yes I think color.module support of sub-themes is not the best, its mentioned in the docs IIRC.

Anyway mytheme_preprocess_node() is probably the way to go..

dshaw’s picture

After lots of trial and error, I got it to work. First solution:

Added this to template.php

/**
  * Define this theme's functions.
  */
function gsw_theme($existing, $type, $theme, $path) {
  return array(
    'terms' => array(
      'arguments' => array('terms' => NULL),
    ),
  );
}

I couldn't for the life of me figure out how to move gsw_terms() into a template file. I used the 'template' argument and a template filename of the right format, but no joy.

Now to investigate the preprocess idea.

gpk’s picture

>Now to investigate the preprocess idea.
which might let you do away with your own theme function... depending what you are trying to achieve... Often you can do what you want by overriding the theme function in question (in this case, by implementing mytheme_links() in template.php), though you might find that preprocess + CSS is sufficient, e.g. in http://api.drupal.org/api/function/template_preprocess_node/6 we have

$variables['terms']     = theme('links', $variables['taxonomy'], array('class' => 'links inline'));

so quite easy in a mytheme_preprocess_node() to add an additional custom class...

dshaw’s picture

All I'm try to achieve is change the presentation of the tags on a node. Typically they are displayed at the bottom of the node separated by spaces. I want them at the top of the node separated by pipe (|).

Modifying node.tpl.php let me re-format the text above the node. It gets me "Created by %user% at %date% on %tags%". The new function formats the tags as I desire.

gpk’s picture

OK, the recommended way would be to keep all PHP calls out of the *.tpl.php (separation of logic from presentation), i.e. put the call to theme('terms',...) in the preprocessor. If theme_terms() doesn't need to be overridden anywhere you could even just 'hardcode' what it does into the variables['terms'] = ... statement in the preprocessor.

But as it's your site at the end of the day it all depends on what you feel like doing ;)

scoutbaker’s picture

This is a duplicate of http://drupal.org/node/613930. Please don't post duplicates.

dshaw’s picture

Apologies, it is a duplicate. I posted to the theme development forum and didn't get a reply. In this forum I got a reply within a couple of hours.

scoutbaker’s picture