I am trying create a summary (custom) page for my Products page. I tried page-products.tpl.php. This page affected Products A to C.

Products
--Product A
--Product B
--Product C

Products is my vocabulary. I have 3 terms.

How do I have a custom page.tpl.php for my vocabulary, Products, not affecting my terms (Products A to C)?

Please advice on my template naming for Products page only.

Thank you.

Comments

mooffie’s picture

You can put the following in your template.php, then use the template file 'page-products-all.tpl.php'.

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      // if we're browing the 'products' url exactly,
      if ($_GET['q'] == 'products') {
        // then tell drupal to use 'page-products-all.tpl.php'.
        $vars['template_files'] = array('page-products-all');
      }
      break;
  }
  return $vars;
}

(Code not tested. Based on this.)

jessicakoh’s picture

Thank you so much, mooffie.

It solved the problem.

elvis2’s picture

Here is another solution. If you are looking to have a specific tpl file for let's say vocabulary 1, then you could use this code:


function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
        
      if(arg(0) == 'taxonomy' && arg(1) == 'term') {
        $vid = taxonomy_get_term(arg(2));
        
        if($vid->vid == 1) {
          $variables['template_files'] = 'page-vocab-special';
        }
        else { // let's just create a generic but specific page for each vocab then
          $variables['template_files'] = 'page-vocab-' . $vid->vid;
        }
      }
        
      break;
  }
  return $vars;
}