Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now we are going to launch into an aspect of Views that lets you add, remove and change features of a view from its displays. So we'll take our people view for example for which we have set up a page, block and feed. Right now they are all showing pretty much the same fields and they are all filtered in the same way and in the same order. That's because they are all based on the Views' Default display with no changes. But we are now going to override some parts of those displays to make them more appropriate for their applications. The Block view will show less information than the Page view because it doesn't have as much space to display it in and we'll sort it differently. They'll share many qualities of the default display, but will diverge in important and useful ways.
That's easier to show than explain. So let's take a look at our Page, Block and Feed, and then we'll change them a little bit. As we go through our displays you will notice some differences, and quite honestly these differences aren't very well documented. We'll talk more about them in upcoming videos, but just very briefly I can point out a few. If we look at the Block display, we see for example this More link that doesn't exist for the Page display. Likewise there is this Link display, which doesn't appear in either the Page display or the Feed display. Some of these differences become important as you start overriding the default settings and we'll show those as we go. But first let's start by changing our Block display.
Now we can override pretty much anything we see here. One problem I had with the Block display was how much information it showed. In fact, let's go and administer blocks and show that Block display here in the right side bar so we can see the changes as we go. You remember we created the block with the administrative name people block. We'll put that in the right side bar and save. Now that's too much for a block. Let's change it by going up to these little ghost menus here and clicking on Edit. One good thing about those ghost menus is when you get back to the Views Administrative page that way it goes directly to the display you want. If you hit the Back button it very often won't. It will go to the Default display instead and you start editing the wrong thing, but here we are at Block.
We don't need all of this information. Let's only list the name. To do that I'll click on the Fields head here and then scroll down. We only have one option. That's to override or to keep the defaults. We click on override and we are told that we are using overridden values. That's a warning. We can always switch back by going back up there and clicking on Use default. But we do want a difference so we'll click on Update. I want to scroll up again and point out something. You see how all of these things are in Italics. That means that they are exactly the same as the Default display. The parts that have changed are shown in non-italics or what's called Roman type.
We are now going to remove all the fields except for that name. There are two ways we can do it, we can do it one at a time, for example clicking on the headshot, scrolling down, and then clicking Remove and then Save, and as you can see we've removed it from that side bar. However, we haven't removed it from the page. Let's go back to our View by going to Administer, Site building, Views and Edit. We can actually take a look at the page and see that the headshots are still there or they are not in the block. We are going to go back and edit that block again.
The other way we can get rid of several fields at once is using this Rearrange button. Click on it, scroll down to our options, I'm going to delete everything except for the title which is the person's name. Note that as we are doing this we are reminded that we are using overridden values. That's very valuable to see because often you'll forget exactly what the default is, what's overridden and so forth. We click Update and Save. And we are back at our page because when you save a view it brings you back to where you were before. That's perfect because now we can see we have the page version here with all the information and the block version here with less information. We could continue to edit this to make it even better. Let's edit that Node title, we don't need to say name before each one, scroll down, get rid of the label, and let's link the field to its node, I often do that, scroll down and Update and Save.
We are back at our page, and we see here one version of the view over here, and another one over here, great. But we can change more than just what fields are showing. You can also change the Sort criteria. So I'll go up here and add a criterion. We wanted to sort so that the most recent ones were at top. That's going to be Node: Post date. There also is Node: Updated date. Either one. Whichever one is appropriate to you. We'll click on Add. The Granularity lets you make it so that things that appeared on the same day or the same month don't seem to have appeared before each other. So you could for example say this is everything that appeared may, (ph) and no one thing seems more important to our earlier than another.
Now we could click on Update default display here, but you notice it says default display, we are still going to be changing the default, and if we make this change now it will happen both on the block and on the page and on the feed. We want it only to happen on the block, so we have to remember to click Override. The other thing I want to point out is Sort order, Ascending or Descending. Sometimes it's hard to tell which is which with dates. Is a later date ascending or is an earlier date ascending? I'm just going to leave it as it is and see what it looks, then I can make my decision. But for now we click Override, Update and Save. We don't actually know which appeared earlier or later, so we could go back and actually add a field. Once again we've already overridden all of the fields, so we'll add one, scroll down and add Node: Post date, Add. Again we are warned that we are not using the default. I'm going to have the Date format say how long ago were these added? And you can change the Time format and so forth, but we'll just go Update and Save. Ah, now we can really see that we actually have the oldest ones appearing at the top. Of course we could go back and change that fairly easily by changing it to Descending. We can also change this field so it doesn't say Post date, why don't we go ahead and do that? We are at the point now where we know Views well enough we can clean them up as we go. I scroll down. Get rid of the label, and Update and Save.
There is one more thing though that we haven't quite done, people don't know what these are, so let's add a title to that block. Edit the block again, and here again you see how it's in Italics. If we add a title here and we don't override, it will be added to the page as well to the block, which won't be appropriate because what we wanted to say is here are the most recent ones. So I'm going to override Recently added, Update and Save, and there we have it.
It's looking better and better. We could continue to make it look good in many ways, I'm just going to do one or two very quick things because this will help un-clutter our page. Items to display, I'm going to change just 3, but remember I have to override, and Update and Save. Now we only have three. I edit it one more time, and I'm going to add a More link, again it's in italics, so we have to be sure that we change that by overriding, Create more link and Update. The More link will add a link to the bottom of that block which will go to the full page, very useful, and incidentally that's also what that link display means. So you can tell the Block view exactly where it should go when somebody clicks on More.
I know I'm throwing out a lot of little things here and will go into many of
them in greater detail later.
But I really want to drive home the idea that you can override things in the
Page, in the Block, in the View so they all look different, and in fact give
much more useful information because they fit their spaces better. As I said I
now have a More link that goes to this page, excellent!
Now the last thing that I want to do is we've created this block I'm actually
going to remove it from that right column, and the reason for that is as we go
through the course you will notice that the View Screen actually gets quite
crowded when you have things in both the left and right column. So I'm going to
go to Administer, Site building, Blocks, scroll down and move that people block
Scroll to the bottom and Save, and let's just go to our homepage so we see everything looks as it did. Displays in a single view could have no resemblance to each other at all. They could have completely different field, sorting, arguments everything. This flexibility introduces an architectural question though. When should you create a new view and when should you just add a display to an existing view? That's a subject of some debate, and it's ultimately decided by your particulars style of web development. Don't worry too much about being wrong. Just develop Views using the way that's clear to you, and that will be clear to any other Drupal Administrator who'll ultimately be working with your views.
Get unlimited access to all courses for just $25/month.Become a member