6. Adapting Php Themes like Chameleon

Last modified: December 8, 2006 - 16:01

The instructions in this section will work for any theme that uses the phptemplate engine. Adapations need to be made if you use a pure php theme like chameleon. Fortunately, it can be done fairly simply.

To make the template described in these pages work in chamelon, go ahead and create the template as described, except change the names of the field names slightly so that they start with $node->. For instance, $field_first_name[0] becomes $node->field_first_name[0] and $location['city'] becomes $node->location['city'];

Drop that template into your theme folder. If you are using the chameleon theme, that folder will be a folder under the chameleon theme folder.

Next, you need to alter the .theme file so that it will discover and use the template you created. If using the chameleon theme, open the file chameleon.theme and look for the following code:

...
function chameleon_node($node, $teaser = 0, $page = 0) {
    $output  = "<div class=\"node\">\n";
...

Change that code to insert a new snippet of code like this:

...
function chameleon_node($node, $teaser = 0, $page = 0) {
  global $theme_key;
 
  $template = dirname(__FILE__) . '/'. $theme_key .'/node-'. $node->type .'.tpl.php';
  if (file_exists($template)) {
    ob_start();
    include($template);
    $output = ob_get_clean();
    return $output;
  }

  $output  = "<div class=\"node\">\n";
...

What that code will do is check to see if a template with a name like 'node-[node type].tpl.php' exists in the theme subfolder. If so, it will include it and return the output, otherwise it will go ahead and process your theme normally.

That's it. Your modified theme should now be displayed.

 
 

Drupal is a registered trademark of Dries Buytaert.