I've created a custom template file for displaying a table (views-view-table-altered.tpl.php). However I found I cannot simply place it in the views/themes folder and see it when i click "information" next to "theme:" in the views edit pane. How would I tell views to use this custom template other then simply replacing the default table template. Thanks!

Comments

merlinofchaos’s picture

Status: Active » Fixed

This is explained in the advanced help topic "Using Views templates" that comes with Views.

clarkwolfe’s picture

Status: Fixed » Active

It seems like it just doesn't see my custom template, despite being named correctly. :-(

I have created a template named more specifically then the default template file as shown in the "theme: information" area. The file is called "views-view-table--user-list.tpl.php" and is in modules/views/themes/ folder. I know this is the right folder because when I delete the default table template and press rescan template files it complains that it can't find the default template, but seems to ignore my template even though it is named correctly. Am I doing something wrong? I have cleared the cache and followed all the advanced help instructions.

merlinofchaos’s picture

Status: Active » Fixed

Important note: You place your custom template files in your theme directory, not views/theme. This is always true of theming with Drupal.

I'm sorry, I don't help people who refuse to read the documentation.

If you don't understand how to use Drupal's theming and template features, you need to read the theming documentation.

clarkwolfe’s picture

Thanks for the help... that you say you don't provide, works now. I'll be out of your hair.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

suthy’s picture

Version: 6.x-2.1 » 6.x-2.6
Status: Closed (fixed) » Active

Ok so I've read a ton of documentation and cannot for the life of me find a way to use a template with a 100% custom name, regardless of the view name. Basically I have 2 views, each with multiple displays. I've created all the necessary templates for the first view and they are working correctly since they follow the standard template name structure. I want to use the exact same templates for my second view, without having to duplicate all the templates and rename them to match the 2nd view name. I've tried doing the following:


function mytheme_preprocess_views_view(&$vars) {
  switch ($vars['view']->name) {
    case 'view_name_two':
        // Use template from first view
        if ($vars['view']->current_display == 'panel_pane_1') {
          $vars['template_files'][] = 'views-view-fields--view-name-one--panel-pane-1';
        }
        dsm($vars['template_files']);
      break;
  }
}

My dsm() gives my the template I said to use. But when I clear caches or rescan templates, the view doesn't use it or recognize it in Theme Information.

I've used theme_render_template before successfully in other preprocess functions, but never in a preprocess_views_view_etc. function. Since the views preprocess functions don't use "return", I don't know if there's another way to call a custom template.

Is there any way to call a specific .tpl.php for a view?

suthy’s picture

This is a pretty urgent issue. Is there really no way to reuse views templates or call templates with whatever name you want? If anyone has input it would be much appreciated.

dawehner’s picture

Mh, the code looks fine, i guess, you are missed to clear the theme registry cache.

suthy’s picture

I've cleared all caches, specifically the theme registry cache several times.. it just won't use a tpl.php that i declare. This doesn't make sense. I was able to force templates in Drupal 5 just fine. Why would this ability drop?

In D5 I would just toss this in the end of my function theme_views_view_list_name_of_view($view, $nodes, $type) ...

return _phptemplate_callback ('name_of_view', $vars);

and it would use name_of_view.tpl.php or whatever I wanted. Something simple must not be working correctly. I would assume I'd be allowed to do something similar with theme_render_template() but it doesn't seem to be the case.

Anyone? merlinofchaos?

suthy’s picture

Status: Active » Closed (fixed)

GOT IT!

http://drupal.org/node/223440

"Suggestions work only when it is placed in the same directory as the base template. Templates can be placed in any sub-directory of the theme. They must be paired into the same location."

We didn't have a views-view.tpl.php in our theme directory. Once I did that, BAM! worked. Knew it was something trivial.