Wednesday, April 20, 2011

change template files based on an cck or an url

Customize templates based on CCK or URL

Drupal6
<?php
function themename_preprocess_page(&$variables) {
//Templete file for each content type
if ($variables['node']->type != "") {
$variables['template_files'][] = "page-node-" . $variables['node']->type;
}
//Seperate Templete file for the path node/3
if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL) && arg(1)==3) {
$variables['template_files'][] = "page-test";
}
}
?>

Drupal 7
<?php

function themeName_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
// If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}
}
?>

1 comment:

  1. Hi,
    thanks for your great tips and tricks, so usefull for me!

    O.

    ReplyDelete