Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Drupal's built-in data presentation tools offer several ways for web designers to clearly and attractively package their data. In Drupal 6: Online Presentation of Data, Tom Geller explains how Drupal handles data so users can set up intelligent structures and implement them with Drupal's Content Construction Kit. Tom also shows how a data-driven web site can improve its interactivity by using geographic data to connect real-world addresses to maps. Exercise files accompany the course.
Now we are going to walk through the creation of a view but with our eyes just on the interface. It should be noted that throughout this course, when we talk about views we are talking about Views Version 2, usually just referred to as Views 2. They were profound interface changes between Version 1 and Version 2 and I expect Views 3 will have further interface differences whenever it comes out. Unless you're using an old Drupal installation, you really don't have to worry. If you downloaded Views after, say, September 2008, it's almost certainly Views 2.
Before we jump in, let's get an overview of the steps to create a view. In short, there are two preliminary screens and then one main screen where all the action happens. The first screen shows a list of all the views that exist already. That includes both of those that you created and those that were included in Views and any modules that you installed. On the second screen, you specify what sort of view you'd like to create and you give it a name. The third screen is the main screen where you decide which records would I like to show in my view, which fields in each record do I want to show, and how exactly do I want them to displayed as a grid, as a table, unformatted, and so forth.
Each of the selections that you make on the main screen have many, many options. Once again, we won't have time to go through all of the options in this course, but we are going to go through a lot of them, and in fact, we are going to be spending several lessons just talking about Views Interface. So there is the theory of it. Now let's actually start stepping through the process. We are going to create a view called Temp that won't actually do much but display a list of Node titles, much like you saw on the video about simple views. Then we'll delete it before leaving this video, ready? To get to the Views Interface, go to Administer, Site Building, and Views. And here we see a list of views that we already created. This first one up here people is one that we created in earlier video just to show you how views are made. I'm going to delete that view and we'll recreate it over the rest of the course, and in fact, we'll improve on it quite a bit.
To delete a view, you click on Delete here, confirm your deletion, and it's gone. The rest of the views that you see on this page, archive, comments_recent, date_browser and so forth, were all created by the module views itself. They are built-in to views. If you enable them, you can then edit them and change the way they look. These built-in views cannot actually be deleted instead you just disable them. They stay there but not available to you. If you've installed the Advanced Help Module, you'll see links throughout Views Interface, which will help you further. One of them is this one here, not sure what to do, try to Getting started page. This is actually quite a useful page when you click on it, it pops-up a Window and explains the Views Interface.
We'll be going through all of these in the course but this is also a useful resource. Now let's get started creating a view. The first thing to do is to click on Add, and here is that second screen I told you about. We are going to call this view temp, and the description will just say Temp. Now this first one is the machine-readable version of the name. It can only contain lowercase letters, underscores and numbers as it has underneath the field. If you'd like you can tag your views so that if you create many, many views, they can be separated into their different areas. We are not going to do that, we are only going to be creating a few views, so we are generally going to skip that View Tag throughout this course.
Growling down further, you have a choice of what type of view you'd like to create. Over 95% of the time, you are going to be creating a Node View. That is something that pulls information from various nodes as opposed to user profiles or filenames or so forth, so we'll leave it there and click Next. Now just as a warning, the view is not saved at this point. In fact, it won't be saved until you explicitly click the Save button which you see down here at the bottom of the main screen. We'll do that once we've configured this view a bit. The main screen is divided up into several areas, which are fairly obvious from their headings: Basic Settings, Relationships, Fields, Filters and so forth.
The first place that I go when I create a view is to Filters because I want to separate out only those nodes that I want to take a look at in the view. To add a Filter, I click on the plus sign here. Remember how I said that Views is contextual. This is an example of that. You click on plus and it opens up an area underneath. This area will change depending on what you clicked above. We now have a choice of what sort of filters to add. Once again we'll go into great details about exactly what these filters mean, later on in the course. For right now, I'm going to Filters, so we only see nodes of the type person.
Remember we created the content type person to store the personal information for the family members we are recording on the site. To find it, I scroll down, I happened to know that it's in the Node group. So I scroll past the Comment group, the Content group that is all of the custom fields that we created, past date and there we are in Node. What I'm looking for is Node Type. I click that checkbox and click Add. Then I have a choice of which types that I want to include in my view. As I said I only want the person content type, so I click that, and then click Update. Once we have done that, we are given a little warning that we started to create a view but it's not complete yet, don't worry about this warning, we'll get past it in just a moment.
But before we add fields to this view, I want to add one more kind of filter. This is something that people often forget to do when they create views. But I find it's almost always something that I want in my views and that's to only show those nodes that have been published. Sometimes when you are working on a site, you'll save some nodes back because you have an Editor who wants to look at them, or something like that. And if you are not careful in views, you could publish all of those unpublished pieces of information. So I'm going to go up to Filters and Add again. Scroll down to Node and Published.
Incidentally, this process of clicking Add and then going through this list of things underneath is something we'll do dozens if not hundreds of times throughout this course, so get used to this interface. I'll scroll down further and click Add, and yes, I want only those that are published. Update again and save, good! Now I'm going to add my fields. As I said, this is going to be an extremely simple view. It's only going to show a list of titles of nodes in that content type person, so we'll just go Add Field, and we are only going to add one and it is Node Title, scroll down and there it is.
I want to mention something here. This little groups pop-up actually makes that scrolling process faster once you get used to where a certain field is. That is, in which group. I know that the one that I want is in the Node group. So I hit this pop-up, go down to Node. It filters, so only those fields in the Node group are available. Some other groups, for example are Comment or User, and as you can see, these are fields that have to do with the user profile, the user login and so forth, but we just want Node. Scroll down to Title because that's what I want to show and I'll say Add.
I am going to leave this field pretty much as it is, except for one thing. I want to link it to its Node. I almost always find that to be most helpful and I'll do that many times through this course. Click on Update and there we have it. We have a live preview down here that shows us what our view will look like, and just as I said, it's pulling all of the titles from the nodes of content type person and putting them in this format. We could then go back and change this format, for example, to remove the word Title from the beginning or to turn-off the link, or to add other information, but that is the essence of Views.
The last thing we want to do here, and in fact, you want to do this frequently while you are building Views is to click Save, because remember, this hasn't been saved and if we left the screen, we would lose it. So click Save, good, and now if we go back to List, we can see that view, temp. If we want to edit it again, we'll just go over to Edit and we are back where we were. When you come back to Edit a View, you might be scrolling down and say wait, where is my preview? Well, it doesn't actually show up until you explicitly say that you want it. So if you come back here and don't see your preview, no big deal, just click Preview, and there it is. I want to point out some other information at the bottom of your preview. It's this Query and all of these statistics here. This is very useful for developers.
The Query is showing what actual SQL commands are being sent to your SQL server. I have often found this query section to actually be useful in learning SQL, so that's another use for Views. Further, if you are running a high traffic site, this information at the bottom of the query build time and execute time and so forth is especially important if you are running a very high traffic site because as you know, saving a few milliseconds here multiplied by a million times ends up being a lot of time saved on your server. There is one other small trick I'm going to show you in Views, and that's how to actually take that view and display it on your site. Let's go back up to the top where we have this Add Display section. This view actually doesn't appear in any useful way on your site, it's just the defaults that will then be applied to other sorts of displays. That display could be a page or it could be a block or it even could be an RSS feed. We are just going to quickly add a page and we get a warning down here, saying, it needs a path, we'll just called this path temp. You set that here under Page Settings, click on Update and once again Save.
Now we can actually see that on our site. If we go up here and change our URL so it's just localhost/temp, there is the page we just created. And as I showed you in the simple views video, when you are an Administrator, you can edit this view very easily by hovering your cursor over the view itself, going up to this ghost menu at the top and clicking on Edit. If you have the exercise files for this course, you will find this graphic in your folder. It shows the Views screen broken up into its sections, I find it a lot less intimidating when I think of it in terms of those sections, and in fact, it operates in that way. When you click on something near the top of the screen, that's when the other stuff below actually starts appearing, so it's sort of a segmented screen.
This top area is where most of the action happens. That's where you decide how you want your view to appear, what field do you want in it, what had to be filtered on, and so forth. When you have clicked on something up here, selection options appear below. Those selection options are specific to whatever you clicked above, going down further you have the buttons that let you save or delete your view. If you start doing something and decide you just want to stop and get out of it, you can also click Cancel. Finally at the bottom, we have the Preview, so you can see your view before you save it, and all of the query and performance details that I mentioned earlier which are very useful for administrators.
There is one other piece up to the top and toward the side and that's to add additional displays. As I mentioned you can turn a View into a page, a block or a feed. The last thing we are going to do before we leave is we are going to go back to our view and clean up after ourselves, a list of views we have, and delete that temp view just like so. Easy, huh? Yeah, I know, not that easy but it will be easy I promise. If you are the sort of person who learns best by doing, you could just go ahead and start poking around Views' many, many options and read some of the documentation that's in Advanced help. But then when you are done with that, come back to the course and learn about a lot of the subtleties in Views that might escape your attention and that aren't really in all of that documentation.
Find answers to the most frequently asked questions about Drupal 6: Online Presentation of Data.
Here are the FAQs that matched your search "":
Q: The exercise files for the course appear to be missing.
A: Full exercise files for this course were not provided because of the unusually large amount of images, modules, and other files that would have to be installed in specific places, in addition to the database. We hope to have a solution for future Drupal courses that installs all items in their correct places.
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.