1

I am trying to organize my theme folder, which has node theming overrides for dozens of views. Basically I have two different styles and I want them all to look the same, more or less.

Is there a way in template.php that I can do this? And what is the best way?

I tried this code in my theme's hook_preprocess_node function:

switch($vars['view']->name) {
 case 'taxonomy_term' :
   switch($vars['view']->current_display) {
     case 'page' :
       array_push($vars['template_files'], 'list-view');
     default :
       break;
   }
   break;
 default :
   break;
}

And when I look in theme developer, I can see the list-view.tpl.php file there, but its not actually using that file from my theme directory. What am I missing?

Pattie Reaves
  • 175
  • 1
  • 3
  • 11

2 Answers2

3

As you can see in theme() Drupal will only actually use a template if it exists according to drupal_discover_template().

You should try to figure out if that is the case.

  • place some debug code in the theme() function in includes/theme.inc to see what drupal_discover_template() returns for vairious template calls.

Can it find it? If not:

  • place some debug code in drupal_discover_template() to find out where Drupal thinks it no longer is a template.

My gut-feeling says that it is due to subdirectories where the template files reside, but which you have not added to the template_files variable: views/lists/some_list.tpl.php is not the same as some_list.tpl.php.

revagomes
  • 152
  • 10
berkes
  • 26,996
  • 27
  • 115
  • 206
1

You need to rebuild the cache for the tpl.php file to be picked up.

junedkazi
  • 519
  • 7
  • 18
  • Even when clear the cache using devel/drush/performance it doesn't work. Nor did trying to register my default template using a hook_theme function. – Pattie Reaves Mar 10 '11 at 19:36
  • I think you need to rescan templates in the views theming information for the view to pick up the templates. – junedkazi Mar 10 '11 at 19:53
  • Also I don't think you need that piece of code. Hope this helps http://drupal.org/node/352970 – junedkazi Mar 10 '11 at 19:56
  • I already know how to name the templates — e.g. node-view-view_name-page.tpl.php, node-view-view_name-page-1.tpl.php — I'm looking for a way to re-use the same template for multiple views so I don't have to create all of those files. – Pattie Reaves Mar 11 '11 at 01:32