Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal theming a row in a view's display

I'm trying to theme a single "display" in a view. What I'm trying to achieve is to have some control over how the row is rendered (eg. print the fields in the row, and maybe add some text in between. along with some divs for styling purpose). I've looked for days for the template to edit. I've used even the Theme Developer and the View's Theme Information, but no luck. All

My view's name is Calendar, and there are a bunch of displays. Could anyone tell me what I should do in order to customize the rows in this particular display? Does drupal even provide this flexibility?

The Name and Title of my display in the Calendar view is:

Name: List view
Title: List

Here's the theme information for row style:

Row style output: views-view-fields.tpl.php, views-view-fields--calendar.tpl.php, views-view-fields--page.tpl.php, views-view-fields--calendar--page.tpl.php, views-view-fields--calendar.tpl.php, views-view-fields--page-1.tpl.php, views-view-fields--calendar--page-1.tpl.php

Could someone tell me how to


Edit:
(Some additional information the OP posted in an answer)

I'm using Drupal 6. I'm not sure what page-1 indicates here The following is the list of display I have in this view:

Defaults 
Calendar page 
Calendar block 
Month view 
Week view 
Block view 
Upcoming 
List view 
Ongoing Block Feed 

As you see, none of which has the string "page-1". I edited views-view-list.tpl.php, one of the file listed for "style output". The only variable I have access to is rows, which is an array containing all individual rendered "row". Like I mentioned before, the rows are generated somewhere else, and already contain the rendered fields. How can I customize these rows?

like image 664
Ronald Avatar asked Oct 30 '09 16:10

Ronald


2 Answers

You shouldn't have to add anything to template.php if you are using Drupal 6.

The list of possible theme files that you have there goes in order from least to most specific. For instance, the first one, views-view-fields.tpl.php, will apply to all fields of all views on your site. The last one, views-view-fields--calendar--page-1.tpl.php, will only apply to the "page 1" display of the "calendar" view, so I'm guessing that's the one you want to overwrite.

When you click on Theme Information in the view, the display provided ("page 1" or whatever) applies to the display you are currently on. So if you want to theme fields in a certain display (the "blocky block" display of the "calendar" view, for instance), then you would click the "blocky block" display in the vertical menu on the left, then click Theme Information for that display.

So once you figure out which one you want to use, make a new file in your theme directory with that name, then copy of the contents of the current theme file (click the name of the theme files section on the Theme Information page) into your new theme file, then edit away. Remember, if you overwrite a theme file, you have to click "Rescan template files" in the Theme Information page for the new file to take effect.

Hope that helps!

like image 135
theunraveler Avatar answered Oct 14 '22 02:10

theunraveler


The displays have custom names on the surface only, but internally they are referenced by id. 'page_1' will be your first display of type 'page' (blocks will become 'block_[id]', feeds will become 'feed_[id]' and so on).

So if you posted your displays in order, 'page_1' would be the 'Calendar' display. You can check this by looking at the links under the display entries in the display listing on the right of the views config page. They will have anchors named '#views-tab-page_1', '#views-tab-block_1' and so on.

As for overriding the templates, be aware that if you add a new *.tpl.php file, you need to reset the theme registry for it to be 'picked up' by Drupal.

like image 1
Henrik Opel Avatar answered Oct 14 '22 02:10

Henrik Opel