How do I make a template file for a specific display in a view when I have multiple displays of the same type - drupal

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!

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:
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

Related

Embedding the view of a url inside the header of another view

Currently, I have a dynamically created custom pie chart located at mywebsite.com/customchart that is created through a module I made using Highcharts.
I have view, that is listed in the views module shown in mywebsite.com/admin/structure/views/view/ which I would like to embed the custom chart into but I cannot find it through Add Header>Global: View area.
How exactly would one be able to achieve this? Programatically? How?
You can do it programmatically.
First you have to find out what template file is used for rendering the header. Easiest way: go editing your view, select proper display and then unfold "Advanced" options block on the right column and click "Theme: information". Here you can see what templates files are used (assuming you are using Drupal 7). The used ones are in bold. You can collect actual template code there so you don't have to find template file at all if you want to override it. And you can see file naming suggestions, so there you have everything you need to override template file.
If your theme is not overriding standard templates then you should do that - it's not good idea to change directly templates provided by Views module.
So, the first part would be finding out where would you like to embed the view, at what template and at what position. Second part is using function views_embed_view() for doing that:
https://api.drupal.org/api/views/views.module/function/views_embed_view/7.x-3.x
As you can see there, first parameter is machine name of the view, second of display and then you can pass parameters if your view accepts them. So call that function from proper place and you'll have your view embedded.
Also, there is display type "embed" which you can use for embedding views like this. It will provide those "edit view" links when you hover your view content while logged in as admin...

Drupal 7: navigation menu with Views?

I want to make a long page consisting of multiple nodes (each of the same Content Type). The page should have navigation on top of it that will allow to jump directly to the desired point of the long page, kind of like here: http://www.apple.com/macbookpro/features.html (there navigation is under the picture)
I used the Views module to assemble a long page from content, and for navigation I tried to use another View of the same content, only inserted in the top of the page as a block. I set this view to display grid of fields; it looks good. Only I could not figure out how to make each cell in the grid to become a link to the content on the same page.
I tried modifying views template, but there $rows variable turned out to be a string with already assembled html. Maybe I could possibly modify the content template, and insert some sort of condition that will change the way content looks based on what part of the page current view is located, but I am not sure how to do that either.
In the views, edit the field selected, and there are options there to configure the field as hyperlinks how you may want them. Also you can just let the field link directly to the node, there is an option for that. cheers

Concatenating 3 views in one page

how could I concatenate 3 views in one page ?
Should I use blocks ?
You can use blocks, but Views provides an attachment display as well. Attachment displays can be attached other other displays within the view. So, you could create your base view, then create an attachment display that attaches to the base view, and then create a second attachment display which attaches to the first attachment display.
Attachment displays are good if each view is really just another way to view the same query (like, a summary view and a detail view). But if you wanted to combine three disparate views, blocks would be the way to go. Either create a block display for each view and add them to the same region in Site Building -> Blocks, or create a page display for one of the views and block displays for the other two.
A third option would be to use View Reference, which lets you reference views as CCK fields, if you needed the views to part of a node.
It probably depends on your layout.
if you want to embed a view in somewhere else besides your block regions, you could try the embed views module I also believe the the panels module has a much more dynamic way of rendering multiple views on the page (but flexibility also adds some to the complexity)

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?
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!
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.
Have you added the custom code needed in the template.php file? I know in drupal 5 you need to put code in 3 files:
template.php
views-views-fields--[name].tpl.php
views-views-fields--[name].css
Also you might try:
http://drupal.org/node/128741
answering the second question: the style output is not the template you're looking for. row style is the template that edits how fields are arranged within the row. if you want to edit how a particular field outputs its content, then the specific field template should be edited.

Drupal: How to show specific view in a particular block

Let's suppose I have created a view that shows some kind of stories.
But I want to show this view in a left-hand bar — not a link to the view, but the view itself.
How can I connect my new view with a fixed block position?
I want to be able to show real view data in various places on my page.
Is it possible or I am limited only to central area and links to views from menu?
Using Views 2.x for Drupal 6.x it's simple to create a block from a view. Every view has a set of 'default' settings and some number of display settings. A display can be a page, a block, a feed or anything else that creative module authors.
To make a block from your view, you just "Add Display" of type "block", override any settings that you want changed in the block (IE - display less items, just a node title, whatever). You then have a block that you can place like any other Drupal block.
edit: Answer to "Can you limit stories to ones that are tagged"? Sure thing. You just add a filter for Taxonomy terms.
Getting a view to display in a block is easy. Once you have created a view and assigned the view as a block position you simply head to blocks in your admin and you'll see the view.
Just select the block and save it. Simple.
If your view doesn't show, check your filters and that the view fields are correct. Usually if they are not showing it is something simple like selecting content published = yes.
You can create views as pages or blocks. As you're not telling exactly which Drupal/Views version you're working with, all I can tell so far is that, after you create the view, you can tell it to display as a block or as a page.
Then go to the blocks settings and set that to the position you want.

Resources