12

Is it possible to override views-view-fields.tpl.php file for a specific view? I've tried creating a views-view-fields--view-name.tpl.php file and have re-scanned template files and cleared the cache with no effect. Similar issue as reported here: http://drupal.org/node/1137942

Though if I name the file views-view-fields.tpl.php in my theme folder, the new file is applied when template files are re-scanned. But this would mean that it applies to all views.

I noticed that views-view-fields.tpl.php is NOT one of the files listed in the Theme Information screen which Views presents.

Can someone definitively tell me that overriding of this file by creating a views-view-fields--view-name.tpl.php (or following similar naming conventions) is not possible/is not supported?

2 Answers 2

4
+50

The order of precedence for the naming convention of the tpl files is from broadest to narrowest in it's scope. Thus the field override for all views is one combination, but you can't change the order, as you have tried, only go more specific. To achieve what you want, the view object is available in the tpl you have created so it is possible to have an if(){} else{} statement in there to filter the views that need the override by inspecting the name/display of the view.

5
  • Not quite sure I understand... Narrower tpl files take precedence over broader tpl files, correct? So views-view--archive.tpl.php which is narrower takes precedence over views-view.tpl.php which is broader?
    – nmc
    Commented Jun 20, 2011 at 14:51
  • Correct, and the scope is limited to the 'set' of tpl files. Notice how they are grouped together, one set of tpl suggestions per field, one for the view etc.
    – codexmas
    Commented Jun 20, 2011 at 14:58
  • 1
    Ok, so I'm wondering why my narrower views-view-fields--view-name.tpl.php is not taken into account/doesn't seem to take precedence over the default, broader views-view-fields.tpl.php?
    – nmc
    Commented Jun 20, 2011 at 15:10
  • 1
    It is not an actual template provided by views. You can't fabricate combinations of views elements to make your own tpl files. The only ones that exist are the ones listed, and they are in the order of precedence. Putting the logic I suggested into your views-view-fields.tpl.php file is the simplest method to do what you want.
    – codexmas
    Commented Jun 20, 2011 at 15:13
  • 1
    Ok, that was the answer I was looking for. I just wanted to verify that Views module does not actually support overriding of the views-view-fields.tpl.php file through the regular naming conventions.
    – nmc
    Commented Jun 20, 2011 at 15:51
7

For views 3 - make sure that under "Format->show" field is selected "Fields" (NOT content)

Than go to views and find "Theme: Information" there you can see list of all template currently used (BOLD) and candidate template files. Find witch tpl.php file you want to use.

Go to views module directory and under "theme" folder you should be able to find base tpl.php for your chosen file. Copy that file in your theme folder. Rename it on naming convention given in Theme:Information.

Rescan template files. If everything is OK views-view-fields.tpl.php should not be bolded anymore. Bolded should be your newly created tpl.php then you can style new tpl.php file as you like.

2
  • Thanks for the reminder; I do have Fields chosen and NOT content. views-view-fields.tpl.php is not one of the files listed in the Theme:Information section hence I was wondering whether I should be able to override this in the same way as the other template files.
    – nmc
    Commented Jun 15, 2011 at 20:10
  • @Nebojsa thank you so much for this answer. I'm a D6/V2 vet and was banging my head on the table for hours trying to get this to work.
    – yitznewton
    Commented Feb 14, 2012 at 3:36

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.