3

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).

2 Answers 2

11

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.

3
  • 1
    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
    Commented Dec 22, 2012 at 15:13
  • Lovely...thanks soo much....I really needed this a lot!
    – SGhosh
    Commented Apr 30, 2013 at 8:57
  • how do I add tag, if I have cloned a view ?
    – echo
    Commented Jun 27, 2015 at 2:38
1

Even for a cloned view, we can add tags (comma separated) and create a common template for multiple views. direction to add tag in views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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