1

I have a view that I am using for articles on the front page (View called Frontpage Top).

in one BLOCK display (named: Top Story) it just selects the most recent article. in the other BLOCK display (named: Top 5 Stories) it selects the 2nd-6th most recent.

I need to make a template for the single top story, and then another to display the other 5.

this template: views-view--Frontpage-Top.tpl.php works, but it's being used for BOTH blocks.

The only way I know how to do this is with multiple views, but these are so closely related I'd like to keep them in one. Is this even possible, and if so what would the filename look like?

it doesn't seem to be documented in Views2 ( http://drupal.org/node/352970 ) and this ( Drupal: Views, can the displays have different styles for the view? ) is close but not the same.

If the "right" way is to create multiple views I am ok with that, but I cannot find a resource saying that and I'd prefer not to if I don't have to.

Thanks!

Community
  • 1
  • 1
Jerzakie
  • 115
  • 1
  • 9

1 Answers1

3

Each display can be themed independently from another. In the Views admin, go to the display you want to customize and click on "Theme: Information". This will show you all possible templates and naming options you have. See the image below:

Views Theming

If you see in the image above, you can create a template for specific displays in a view. For example, all of my displays in this view are Page displays. So to style the "Business Cards" display (the 2nd display), I could use "views-view-grid--Vendors--page-2.tpl.php" to change the Style Output. The page-2 specifies that you want the template to handle your 2nd page display in this view.

If you need more information, take a look at Views 2 Theming Documentation

Laxman13
  • 5,226
  • 3
  • 23
  • 27
  • Unfortunately that doesn't solve the problem. I need a way to specify the actual DISPLAY by name, not just the VIEW and the display type. – Jerzakie Feb 02 '12 at 14:26
  • Please see my edits. You can in fact have a template for a specific display within a view. Make sure to rescan the template files in order for it to work. Questions, let me know – Laxman13 Feb 02 '12 at 14:42
  • ok, lets call the view MYVIEW, the DISPLAYS are both BLOCK types called BLOCK_A and BLOCK_B, I need to be able to do something like: views-view-MYVIEW-BLOCK_A.tpl.php (which would have the markup for just the BLOCK_A display in MYVIEW) views-view-MYVIEW-BLOCK_B.tpl.php (which would have the markup for just the BLOCK_B display in MYVIEW) that convention doesn't work but that's what I am trying to do. I don't have paged results for this view. I am trying to put two BLOCK type DISPLAYS from the same VIEW on a single page, and style them differently. – Jerzakie Feb 02 '12 at 15:28
  • I understand. The page display was simply an example. The same goes for block displays. See the new image I put in my answer above, it is a screenshot of your example. In the template file name I gave you earlier, all you need to do is change "page" to "block". Like I said, if you go to _Theme: Information_ you can see all available template names. – Laxman13 Feb 02 '12 at 15:37
  • So the names are in a numeric order based on their position in the view? BLOCK_A = views-view--MYVIEW--block-1.php.tpl, BLOCK_B = views-view--MYVIEW--block-2.php.tpl , and if I added a BLOCK_C it would be views-view--MYVIEW--block-3.php.tpl ? – Jerzakie Feb 02 '12 at 15:42
  • That _should_ be the case, ordered by display-type and when they were created. However, if you look in Theme: Information like I said, it will tell you what number to use, so you don't have to guess. – Laxman13 Feb 02 '12 at 15:47
  • Yeah, I see the difference in there. I will try that out! – Jerzakie Feb 02 '12 at 15:49
  • That worked. The issue I was experiencing was that I had another file overriding those (another template file), I deleted it and did the -1, and -2 files and lo and behold it works. Thank you so much. That's a really odd convention for them to use. I wonder why they don't let you specify the actual display by name rather than using that index. Thanks again! – Jerzakie Feb 03 '12 at 01:14