Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Views allows you to customize output with tpl.php files.

My theme directory is getting overloaded with the .tpl.php files! Many of the files repeat the same content.

I would like to use the same tpl.php file for multiple Views. How can I do this?

Ideally, I would like to call a template file when a tag has been applied to a View.


Steps I have Tried

Use Multiple Views displays: This thread suggests putting all the Views that use the same template file into one view and then creating separate Views displays for them.

This isn't practical for my situation, as my Views have very different fields, which would result in a lot of overriding (which makes them harder to manage).

Views Pre Process This article suggests to use a Pre Process function. You can then select specific views and use a theme hook suggestion to load template files. However, the code it provides is incomplete, so it's not clear how to load the template files. It's also not clear how to load different field/row/display/style templates for a single view (as a View template can take one of a field, row, display or style template).

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

In Views 3 you can add tag “template1” to your views and create template views-view--template1.tpl.php.

enter image description here

Multiple tags supported.

share|improve this answer
    
Excellent! Best of all, if you place a comma between your tags, you get given multiple tpl suggestions! Wonderful! Thanks for your help! –  big_smile Dec 22 '12 at 15:13
    
Lovely...thanks soo much....I really needed this a lot! –  SGhosh Apr 30 '13 at 8:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.