Community Documentation

6. Adapting Php Themes like Chameleon

Last updated December 8, 2006. Created by KarenS on May 18, 2006.
Edited by sepeck. Log in to edit this page.

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.

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x
Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.