Views Mini-Course, Part II: Creating Flexible Views with Drupal 7 [May 8, 2013]

Click to see video transcript

Hannah Corey: Today’s webinar is Views Mini - Course Part II: Creating Flexible Views with Drupal 7 with our manager of training, Heather James. We’re really excited to have her doing the series with us. I’m Hannah Corey. I’m a marketing specialist here.

Heather James: So this is me. I'm Heather James, as Hannah was saying, manager of training the program at Acquia. Our training program, you can see the events there up on the website, we have them all over the world. I actually counted 80 events just in the U.S. upcoming in the next couple of months. Our course materials are actually maintained in-house and we’re continuously updating them. It lets us keep on top of the latest developments and make sure it’s fresh as well. Our trainers are actually our partners. So these are folks who are experienced developers. I have to say - I love to say, they actually like getting away from behind the computer and helping people. They’re the kind of people that others in their company go to for help. So as subject matter experts, they’re really good. We can also provide tailored packages as well for your teams. So please contact me if you have questions.

So we’re in the second part of the Views Mini Course: How to Build Flexible Views. Next week is the last part of this course. These three parts are just an introduction. Views is such a powerful module. I could go on forever on Views probably. After that we’re going to follow up with one class, just on how to configure accounts in Drupal. Something quite simple but people often get a lot wrong with it. Then we’re going to have a four-part mini course for product managers. So I'm very excited about the folks - my colleagues who are going to be helping out on that course this summer.

So what we’re going to do today is look at how to build flexible views. We’re going to see relationships, attachments, contextual filters. So probably things you may have heard of before and hopefully some things you haven’t considered yet. So if you’re watching this webinar, you need to know a bit Drupal already such as how to add content, customizing content types, installing and configuring modules. So we’re sort of picking up from last week as well. So I’ve already explained how Views work and how to add a new View and just manage displays.

So just to recap what we covered, if you go to j.mp/acquiaviews1, I've got all the notes from last week’s class up there. You’ll be able to follow along with what we did. There’s also the recording as well. So what we covered last week were the main concepts of the workflow. If you need to think about Views, think of it in two parts: first what you’re selecting and then how it should appear. So we talked a bit about selecting a base table and then applying various filters and then choosing formats and displays. So just keep that workflow in mind. You’re choosing what you’re querying, you’re limiting your selection and then selecting formatting and displays. As long as you understand at this stage that Views is a query builder, then we’re set to go and we can continue on and dig deeply into the Views UI.

So one thing I said about the Views UI last week was that the Views wizard disappears. So I’m really not going to focus on the Views wizard. Just think of it as a way to get your quickest settings completed but quickly you’ll be moving into the advanced Views editor. So we’ll spend a lot of our time there. This is how we sort of broke this up last week into these two mains section, what to filter and how to format and display. So we’re going to look at, for example, field formatting, filter criteria and how you can actually expose filters, sorting and how you use sorting, for example, in tables, and we’re going to look at contextual filters, number four, and relationships, number five.

We’re also going to look at - I did touch already on attachments last week because I had a little bit of extra time. So I will touch on that briefly. We’re going to focus a lot on number two, formatting. Then in three and four we’re going to look at the page settings and how you get access control, and number five as highlighted there, the pager, and number six, exposed forms. We’re probably not going to use those much in the session but just to call your attention to it.

So let’s look at formatting and display. There are a number of formats available. You’ve already seen me use, for example, the HTML list last week or the unformatted list as well. There’s also something called a jump menu. So in this example, on my site, I got - showing here in this block a level jump menu. You might have beginner, intermediate and advanced. So that’s one example of how you could use the jump menu with the taxonomy terms.

There’s also table formatting. So table formatting lets you actually put each individual field as a row in your table. When you’re doing your table formatting, just as a tip, make sure you customizing labels and making those columns sortable. People generally expect with dates that they descend in order from most recent on top down. So just try and use these sorts of standardized controls. I’m going to give you a demo but I just want to say as a note, if you’re going to add, for example, a new table, think about how your users are already accessing the table base data. So, for example, we have the title, then the date, then the operations, for example. So if I’m going to add another admin view, I should follow that same order. Overall, just with anything you add in Views, just be consistent across your site. If you also find with Views that you’re doing a lot of custom formatting such as rewriting output fields or, in this case, you can see it’s quite small in the screen, how to do a custom date format. You might use this little J, big N, little Y to change how your short date show up, if you’re familiar with that PHP formatting. If you find yourself doing this kind of thing a lot using this custom date format, then change it across the whole site. Go into your date and time settings and change the format or add a custom format for your short date and change the short dates all across your site. So you really want to think about that reusability. So instead of going and trying to do it custom every time, use the short format that you’ve customized just all across the site. In general, we’ll kind of keep that in mind as I do the demos today. Just try to think of reusability all across your - as you’re developing, I should say.

As well, use the default view mode. So if you find yourself doing a lot of field configuration and display configuration within Views, you might be interested in trying display suite to create these custom view modes. I had decided not to go into display suite today because I think it might make a good class on it is own and there are some great materials out there for display suite but just so you can know. The view modes - we talked a bit about this last week. Here’s a teaser and the full content for some website here. Try to use the display suite view modes instead of always of doing fields formatting and views. I guess this just goes to the point, try and reuse the image styles across multiple different areas on your site. It's going to make everything so much easier. So just as a principle with Views, be consistent, think of reusability, think of who can access it, who’s actually going to use the content, and how they need to access it.

So speaking of access, I wanted to just first mention that we should consider, when we’re creating Views, who’s actually going to get access to the content. We’ll actually be looking at this in more detail in my first demo. I should call your attention to the fact that if you’re going to set by access, it’s most easy to do it by specific permission rather than a role. You may be tempted to say, “Oh, give all administrators the access to this” or “all editors access to this.” You may find in the future, you’ll add another role who has some more permission. So do it by, for example, permission, in this case, whoever can access the content overview page for example.

So the next point is filters. So filters actually - mainly what we’re doing with filters is limiting the selection across the whole site. I’m giving you an example here of an exposed filter because I think you saw filters last week. What I didn’t show you was actually sharing it across the site - I’m sorry - sharing the access to the filter with peer users, that’s what I mean to say. So in this screenshot you can see that someone can type in an author name and apply it and see just the list of that author’s content. So I’m going to do a demo just to show you that. We’re going to edit an existing view I’ve created and we’re going to expose the filter to viewers and even insert an edit link for administrators and change the path and the access control as well. So I’m just going to go to my site here. So I’ll go to my structure Views list here and I’m going to go to content by user. So here’s a view I made earlier.

First I’m going to show you what it looks like from here. I’ll show you what I setup first. So I made a list of content. Not a user list but actually a content list. So we have the fields, titles and post date and it's formatted as a table. So I’ll show you what that looks like. So this is just showing me all the content across the site. What I can see is if I pick a specific author and start typing their username and click apply, then I can just see all that content by the author. The reason I made this is because when I go to my normal content list, one thing I find frustrating is that there’s no way for me to browse the content by author and can’t even sort on this author field. So as a content editor or site editor I find this really difficult. So what I’ve created is another view, and you can see how it’s showing up here in my administration interface. It’s actually showing up as a tab on my content menu here. I made it so I can browse. So what I’m going to do to this is add an edit link here. We’ll develop that throughout the class today.

So let me show you, first of all, how we expose that filter. So the filter we added was the author ID and I could have specified a specific author. I’m just going to deselect that there. I could say, for example, just show me content by a specific author, site admin, for example. Instead, if I expose it that let's anyone who’s looking at it to choose their author. So do author name and I can say type the author’s user ID, username. So here we go. So let’s see how that looks now. So you can start to see how it gets much more helpful. I’m going to add another field here which is going to be an edit link. So we often think of all the different ways that you use Views on your site but the administrative views are really helpful. So there we have the edit link. Cool. So it’s getting somewhere now. I’m going to save it and then just refresh this and see what changes we have made. There we have the link showing up. The other thing I probably want to do, as I was talking before about table formatting, is letting people sort. So I’m going to change it so you can sort on the title. So I go into the table settings for that. I can make that field sortable. As I was mentioning before about date sorting, people expect that the default order is descending. So I’m going to make the post date the default and I’m going to make the most recent stuff show first. So I can save that and refresh and see what changes there are. So now the content is sortable by title and by date.

So I'm just going to go back to my presentation briefly and talk a little bit about pagers. I will actually talk to you about the menus to tell you how I got that menu up there but we’re just moving swiftly along. On your Views, you’ll have to decide whether or not you need pagers. Here, I've show you the configuration options. For example, for this block here, on the right where I’ve actually set it to have a mini pager and just show me three items. If you’ve been using a lot of websites now as well, you probably noticed the infinite scroll. I didn’t install that module myself because it gives me vertigo but it’s very popular. It simply means that instead of having a pager at the bottom, it would continue to load the additional - to load the additional list. I'm going to give you a demo of that block just on the site so you can see how that works with the Ajax loading for the sidebars. Then I go back to look at the site here and I can see that news article block in the side. Hopefully you can see that okay. So the Ajax loading means that I can load the next list of content without having to reload the whole page because it’s actually pulled in all the results. So I’m going to edit that view and show you where that setting is. So I'll go down to advanced and look at Views, Ajax, yes. It’s really a simple toggle of yes or no. By doing that, like I said, all the content gets loaded. So what you don’t want to do is use that setting on, say, a view that lists all the content on your site. That would be a lot of content at once. You want to be careful, I suppose. I think it’s pretty useful in the sidebars though, sidebar blocks too.

Now I’ll show you the attachments. We did talk about this briefly last week. I gave the example of listing the news articles on their site and then having just the titles of these, say, older articles. That just allows us to get more content up and probably makes it a little easier to browse. So let’s just look at what we did last week. So here are our news articles on the front page. I have three or two articles showing up and then three articles showing up in the attachment here. So I’m just going to edit the view. Here is the regular list. So that’s just showing us two items. That’s showing an unformatted list. I’m just going to scroll down so you can see. Fantastic. These are kind of - it’s just showing the title, the updated date and image. The attachment - if it loads today - is attached to that display. So when you do your attachment positions, you can actually choose whether it’s before or after, whether it, obviously, inherits different filters you set. Then, finally, you can set it to skip three or I should actually say skip two in my case because I’m only listing two items of content. So that basically lists the upcoming kind of older news, for example. Save it and go down. As soon as it refreshes - we’re getting more news now. At least.

Okay. So then I want to show you relationships. So we spoke about this last week that the first decision you make, especially when you select the Wizard is what your base table is. That’s content - sorry - content or users or taxonomy terms. You can’t change that later but what you can do is get other data from other tables. So say, for example, you’re making a list of users. You would not have access to any content because you wouldn’t - it’s the user table. So what you actually do is make it join on what content was authored by a specific user. Here’s an example where we’re using a module called Entity Reference. Entity Reference actually is on the job listing and there’s a company referenced, there's another type of content node of any selection they want.

So in this example, that becomes a type of relationship you can reference. I think it’s a little confusing until you actually see the demo. So what I’ll do is actually just do a demo and show you what happens when you add a relationship to something. So let’s see. I’m going to go to my structure Views and we’ll say, add a new view, and we’re going to say user list, busy, busy users. So we’re going to show a user list and we have a page automatically created. As you can see, that was my base table, the choice user. I won’t be able to change that later. So we’ll see here, if I want to add some additional fields, let’s say I want to add the user’s name - that’s not showing up for some bizarre reason. I’m just going to cancel this and see why that happened. I’m not sure. So add new view. Add busy users, users and - I actually didn’t check the display format. I really meant to choose fields. So the calendar at the end is available because I have another module that’s installed which I’ll show you later, which is calendar.

So here we have a list of usernames. So cool. It got usernames here. I only want to see the users that have posted content recently, and I want to see what that content is. So, say, a title from a recent post. So if I go to fields here and I look for something like titles - it’s not showing up - or content, nothing, and say, article. Nothing is showing up in terms of anything related to - kind of like nothing related to content will show up because I’m just in the user table. As we can see, the only thing that’s available are user fields. I’m just kind of belaboring the point of it. So what we’re going to do is add relationship. In case we’re adding it by author. There are so many relationships that you could actually add. I think that what you probably want to do is when you add another module such as Flag or Entity, is to see what relationships became available. In this case we’re just going to stick with nodes. So we can see now the user content that’s been authored by a specific user.

Now, when I go to add field, I should see content title. So now that - as you saw before when I tried to get anything related to content it wasn’t available but now it is. So just to move things along a little bit, you can see here I have some users that have no content and some users are actually quite busy. I’m just going to go jump ahead to this one I've made earlier because I just want to speed things up a little bit to save the time. So what we’ve done here is that we’re actually using the latest post as a way to filter. We don’t want to see people who haven’t posted to content. Remember it’s just showing the busy people and we only want to see content of course or recipe type. I don’t really want to - I don’t care if some site administrators have posted a basic page on the site. I want to see those who are contributing new content. So that’s actually used then as a filter to kind of filter out anybody who is not busy. So we can see a specific user and then we can see their actual - whatever content they’ve post. So we can actually - I think I should rearrange those fields so it makes a little more sense. Username, picture, role. Here we go. So you get a username, what their role is and then what their latest post was. It wouldn’t have been possible without their relationship. I've got so many things to show you. Let’s see how much time we have.

Okay. The next thing is contextual filters. I guess this is probably something that is so widely used and I think it’s kind of confusing at first. To be honest, a lot of the configuration is honestly confusing. The terminology doesn’t make a lot of sense. I know they worked really hard on it but we’ll just work through it slowly. So I want to give you an example of our site where we’re looking at a course called cake decorating. This is an all level course. I want to see any recipes that are also related to all levels. So that would be an example of using a contextual filter. Another contextual filter example would be - I’ll show you on the website, our own website. If you look at my user profile, you can see my recent blog post. So what it’s doing there is looking at every single user, basically they’re checking by their user ID. Is there any content by this user ID when we’re looking at this user’s profile? Let’s list it out here. So in the previous class someone was asking “What if you want to have 250 views?” My guess is that if you want to have that many views it’s something you can do programmatically like this using contextual filters. So let’s think of it that way. It’s sort of a way you can get through a lot of content. Let me see.

Okay. I’ll just do a demo really quick. I think I got time. To show you - using a block view, we’re going to pull in a user ID and select, sort and format the content. We’re going to do that user profile. I can also show you the recipes one as well. So I’m going to go back to - look at our user page. Let’s say we look at a particular user here. We don’t see any content by this user just yet. So what we’d like to do is have a list of their titles, anything that they posted to the site. So I’m going to go to structure views. Probably at this stage you have a pretty close idea of what I’m going to do now. You’re now going to go show content. I’m going to show – I’ll type all. I’m quite happy to do that. I don’t need a page, actually, in this case. Probably the first time we’re just seeing - creating a block. We’ll do an HTML list of titles which is good enough for our needs now. So as that is, actually just from having done that, I just want to show you. I'm going to click save because it is quite helpful to see. Just from having done that one thing using the wizard, making a block, a block is now available under structure blocks. User content list here. I can actually place it right under my content. So here is my page content. I'm going to show it on the user content list. So if I go to my user profile I’m going to go by - look at this user again. We’re seeing all the content by all the users on probably all the pages. So we don’t want that, right? We want to limit that block to only show up on user profile pages which in this case - let’s go back to user page. We’ll be under users as a path so we’ll use that.

You can also set that block to show up only on specific content types or for specific rules. In this case, we’ll only list it on pages that start with users. I’m putting in the wild card there. /and * makes the wild card. So we’ll use - those work for anything like a user profile. So I go to refresh here, still seeing it on the test editor page but I am not seeing it on, for example, my homepage. Okay. Cool. So let me go back to that user content list here. I’m going to edit the view from here. So you may have seen this or see me do this before using the contextual link. It's kind of a quick link. What we’ll have now is a chance to just filter out whatever that user’s content is. So we looked at the users/ and then the username, and that’s what is in the URL and that’s what is available to Drupal. So we’re going to look at it - the author ID. As you probably guess, there is no other filter available because this is the content view. This is not a user view so none of the other user information is available. So we’re going to use a user ID from URL. That’s when the filter is not available. When the filter is available we will specify validation criteria. That will be to a user. I have user and we don’t have to do anything. Okay. How to handle it if doesn’t validate. So if there isn’t anything, you can just hide the content or you could have something like a no result found message. I'm going to leave that. Actually, I have a better example of that later. So we will - I’m just going to double check here. Okay. It should be okay. As you see in the preview here, we’re not getting anything actually showing up because we don’t have a user’s ID setup. So if I put any user ID and click update preview, it’s going to check by that user one which happens to be like the site admin. I think there's probably a user two. We’re seeing different content, and user three just to show you. Here we go. So we’re seeing different content by different users. That’s not going to impress you, really, until you actually see it in that user’s page. So after I click save you’ll notice I’m brought back to the view where I was editing it. So here we’re seeing the user - test editor’s content.

Let’s prove it by looking at another user’s content. So we’ll go - which one did she or he not edit? Okay. We did all of this. It's the same user. Here’s the test editor and we can see this user’s content list. So this is taking the user’s ID from the URL and changing what’s available or what’s displayed based on that contextual filter, whatever that context is. One thing - I guess I’ll - I think I have some more things to show you. There’s more fun stuff to show you there. Sorry. You know demos are so fun. I'm just going to show you the related recipes because I think that’s another example that’s helpful. So say, for example, you're looking at a particular course such as introductory baking which is available, I think, I said to all levels for this example here, that's the term. Here's the related recipes by all levels. So I'm just going to edit that view and show you how that works. So this is, again, it is actually just a block view as well. Here we have the - contextual filter is actually the level. So that's the related - you can think of it as the related field between the two pieces of content that I'm relating. So courses and recipes both have levels in them. Here I can show anything that’s related by the specific vocabulary. So there's option there for vocabulary where you can load the default filter from the term page, load it up from the node pages, so that's good for related taxonomy block. That's kind of the key thing you need to do. In my case I limited just by specific vocabulary but you can imagine by selecting multiple vocabularies, you can actually have a much more organic way to relate content all across your site. I also overwrote the title in this case. So when we see the block, you'll see this basically the level name is being pulled in to the block title. So there we go. That is - the last part is defining the validation criteria when a filter is available.

What I thought was useful to do is if there are no results, you can display the content of no results found. If we go back - I haven't shown you this yet but if you go to no results found, you can have, for example, just text message: “There were no related recipes, why not add one?” You can add a link then to your - to prompt someone, if there is no content, at least try and go and add some content. So you can think of ways to encourage content creation instead of saying there's no results here. So this is what would show up if there were no results in there.

Okay. The last thing I'll show - no, there's a few more things I want to show you - is adding a link to your menu. So you can actually create menus with your Views as well, menu tabs. You can also create a link from Views to any of your existing menus. So I think this is something that’s actually quite often overlooked. I wanted to show you how to do this because, especially if you're making administrative Views, you may want to leverage that. So in this case I added the content by user as a menu tab, in fact not just a normal menu entry, as you might do in other examples. I put it into the management menu. The actual path, the page settings, the path, is part of what determines where your menu is going to show up in the future as well. I'll give you another example of that too. What happens in this case for this view is that the tab shows up under the content list. I've also noted here that the permissions is something we talked about before but that is also going to make sure that it shows up in my admin area and only administrators can access this view. So that is the access to the content overview page.

So another - I think I may have shown this to you last week. It's interesting to me because it's something I use all the time, is sort of - this is actually a menu created with Views. So if I go - this is on my website and it's actually built on Drupal 6 but I think it's useful to see because it's just quite handy if they have events in Europe or Canadian events. So I will go to edit this view and show you how that works. So as our menu tab here, for example, the tab is Canada, it's a menu tab and I have set the weight, for example. I've done the same thing for Europe. I've added a menu tab. Still loading] options for Canada. It's the same thing for Europe, added a menu tab and put in the link there. What they're doing, actually, in the view is showing up as links between each other, between each of the displays. The defaults - I'm sorry. The default tab here is set as the U.S. - I'm sorry. The U.S. - the default tab is actually set by the top level menu item or - sorry - the top level of the path. So that's events/ and every other one of them is showing up the child items basically, if that makes sense. I hope that shows maybe a bit - if I go back and look at the view it might make a little more sense. So these individual displays are actually just links between each other in the menu tabs, using menu tabs.

Okay. So I will show you this to demo how to add a menu to your – how to link to one of your menus. I'll also show you how this one works, the content by user one works. So back to our - right here. If I go to the content list - I'll show you, I've already set this up but I'll just go and click edit view from here. You can see the menu option is set as a menu tab within the management menu. So it's going to look for who the parents are in this case. I could have also done a normal menu entry, in which case it won't show up as a tab. I'll give you an example of a normal menu entry now. I'm going to go to structure, views, and I'll give you a recipes. We have a lot of my recipes here, and I'll add this. What I'll do is add it into the menu. I'll show you where I want it to show up, actually, first. That's probably useful. Go back to home. So I got this top of the menu here about all courses, home. So this is my main menu. So what I was going to do is in my menu settings, do a normal menu entry, my recipes, and set it to be in the main menu. I can have it be heavier or lower. Negative numbers are going to bounce up. So I'll put this as a heavier number. So let's see how that works. Save that and go back to my front page. You'll see the menu showing up there. Like I said, you could actually place that link anywhere on your site. On my own training site, I don’t know if I still have it up - never mind - I use that to put in administrative links as well. So there you go. That is just briefly how you can add in menus. You can create as many menus as you like.

Okay. So there are actually so many modules that really love Views and work very well with Views. There's a lot that actually give you templates, calendar is one of these modules. It actually creates kind of quick and easy templates. I'm just going to give you a sense of how that works really quickly. So it used to be - if you're familiar with calendar from Drupal 6, it used to be that it would create kind of a format or field formatter but now it's not. So I'm going to show you. Under structure views, you see here we have add new view, we also have from templates. So this is sort of new with Views 3 if you're new to it. Here we can see, for example, calendar templates as an option. So I can actually create a calendar view of specific fields. Here's field date or last comment or - we’ll just show created field in the - or field date in the node base table I guess would be an example. I think this field date is actually a good example because it's related to my courses and it's not related to my content, just my regular content updated dates. So here we see in the calendar and here we can see an upcoming course. Well, there's one upcoming course anyway. That's basically what calendar does. It creates these kind of quick and easy to make Views templates. It does allow you to do quite a bit customization. I think the great thing is that it comes with all the CSF, formatting just works and it's really a quick way. You could use this to browse content on your site. You could also use it to, obviously, show events listings like that. There are a lot of different displays, week, day, et cetera, that are available. So I'm just going to publish this. [Or save it I should say, and I'm going to click to view week. You can see that similar to the menus I showed you in my Drupal 6 site, you can see how this multiple displays are showing up as menu tabs. So that's quite helpful. Okay. So that's the calendar module.

There's a lot of different ones actually that use jQuery, for example. There's probably as many modules almost as there are jQuery plug-ins, it seems I think, of these types of plug in. The most popular one that I'm aware of I think is slideshow. This is a really handy tool. It's actually giving you another format. So I showed you the jump menu or the table. Slideshow becomes one of the options you have. So you can select how quickly it goes. You can select even the image type. You can even have - text can be in the slideshow. It doesn’t necessarily have to be in pictures, I suppose.

I wanted to talk quickly about the various modules that assist administrators. This is something that is often forgotten when site building with Drupal. It's so worrying because when you see the regular content list in Drupal, it's just - there’s so little you can do with it and it's hard to configure. I even get frustrated just not being able to see my own content so I almost insist on every site that there's some way you can see your own content. So here we see the example of Views bulk operations. I'm actually going to do a demo for you. I want to show you quickly Workbench is another one of these modules, similar to calendar which is actually built with Views. So Workbench is actually a set of views. They just work out of the box. It gives you a list of your own content. It gives you quick access to probably everything that you want to see when you are a content editor, what you've edited, what you've added and quick links to edit content. So it almost seems to me a given. If you're going to build a Drupal site, you'd probably want to put Workbench on it. It's such a handy tool.

If you want to take it a step further, Views bulk operations is super helpful. I feel like I use it all the time. I've got - I had a user put in 20 different items of content, and there was error in every single one but I was able to use Views bulk operations and actually change the value of a specific field, very quickly. So it definitely saves a lot of time. So what I'm going to show you - I'm just going to give you quick introduction to it first, is that Views bulk operations is a field once you've enabled the module. It's creates a field type. Then what you do is you change what operations are available in that field. So I'm just going to show you how to do that. We’re going to go back to my content list by users. I'm going to go to content. You can see my content by user there, and edit my view. So I'll just tell you what we’re going to do. We’re going to add an operations link similar to what we see on our content list here. We’re going to have a selection link which is our Views bulk operations field. Then we’re going to have some options to allow some changing of the content, so some kind of managing tools. So we’ll go to fields - I guess it's sort of belaboring the point to say that I've been enable - installed and enabled the Views bulk operations module and all the dependencies as well. So this is the bulk operations field you're looking for. So I will apply it.

I'm going to change - or selected bulk operations. You can see, for example, unpublishing content might be something you want to do and saving content or maybe removing content from the front page, publishing content, promoting something to the front page. You can see how just being able to do these simple operations can be very time saving. Changing the author is something you might often do. That's quite helpful. So we’ll just slide up and see how see how it goes. Here we get the operations link that's showing up on the side. Remember what I said before about being consistent. People will expect the operations list or check boxes are on the left. So always think about that when you're adding in new fields. So move that over to the left, apply it, and here I've got my select button there, and here are my operations available to me.

Now, you're probably thinking, “Why aren't all administration pages overtaken completely by Views?” Well, in fact, that's what that module admin Views does. So you'd be able to say - it actually overwrites all of administration lists. So definitely check out admin views as an alternative. Here we go. We’re going to see - I can actually see - I can't see the specific author I've selected. I guess if I'm looking at something by site admin, I'm probably clear that this is site admin content but I might actually want to add in the field. I've just realized that might make a little more sense. I'm going to add a field to show the author or the author username. So similar to that problem we had before, author names showing - oh, author ID, ha-ha. I'm not getting the author name because the author name is not available for me. Can you guess probably what I need to do to get that? You're probably thinking “Hmm. How am I going to get the author name here?” You probably guessed I need to add a contextual filter and I'll need to do that on the author ID. So this is just proving the point that if user information was not available - that's not a contextual filter. Excuse me. You want to add a relationship. I hope nobody is taking notes. I'm sorry about that folks. You probably realized what I was doing wrong. So the content author is what we’re looking for. So that's relationship we’re trying to create here.

So now when I go to add a field - someone is laughing at me. I can see the smile. That's great. You caught that, didn’t you? So now we can see the author username is available. So the username is now available instead of just the author ID. So that's far better than what we had before. It's a little more user friendly. So fine that it's there, I think I definitely want to move it over just to finish this off, I guess. I'm going to remove this and move this up and apply to all displays. So there you go. So now you could see - all right. I want to select by just text editor and maybe change the author of a specific piece of content. Okay. So that was good. You got another bonus example of seeing relationships which is great.

So we've got just a few minutes left but I want to go through very quickly, the things we’ll be doing next. So last week, if you watched this class or the last class, you made a view, right? This week as your assignment, please try to add a display that has an attachment with it and maybe use the contextual filter or user relationship to get other data, and add a link to somewhere on your site. If any of the stuff that you've seen today is confusing, I have actually made a tutorial that's in four parts. They're about five minutes each but it goes through contextual filters and using attachments. It's literally 20 minutes long, step by step, very clear. So not as much detail about some of the best practices we talked about today, but there's also a webinar that was just last week with our partners, Suzanne Kennedy from Evolving Web. They have a course, actually, at DrupalCon on Mastering Views Configuration. If you can imagine what we covered and I was able to squeeze in to an hour, if you do a full day long class, you'll get a lot more out of Views. So there's also - this is all in the - the slides we will be uploading as well. You'll be able to get these links easily.

So next week, I'm going to show you how to build your first module with a backup Views. I timed in. In fact, it wasn’t even an hour long. I had to come up with other fun stuff to do next week. Do sign up as well for the following class about configuring accounts in Drupal. It doesn’t like fun but it is interesting and it is really important. We’re going to talk about profile fields and user accounts and roles, a lot of different aspects of accounts on Drupal. Then after that, I think you'd be interested - you might be interested or maybe one of your colleagues is on the project for - Drupal for project managers course.

So next week’s topic, we’re going to do a Views QA. We’re going to go through some views and look at - try and improve the quality of them by going through a checklist. We’re going to talk about theming Views as well. So I want to show and break apart the basic steps of how you go about theming Views. Then we’re going to talk a bit - we did last week and touch on it but formatting and how you configure your formatting. We’re going to do the final steps for caching and performance to improve how your Views actually cache content and load very quickly. Then we’ll build a module to back up your Views. So if you’ve never done anything to back up your Views before, you’ll be really excited to see this. If you’ve never build a module it is super simple and you’ll be very happy you’ve done it. So there’s a lot of events in person as well so please do check them out.

Are there any questions? I haven’t been able to see. There's about a few minutes left.

Hannah Corey: Yes. We had a couple of question come in. The first question is about column sorting. If there is paging, will the sort consider a current page only or the whole set?

Heather James: It will - the sorting will be set across any pages, any subsequent pages. So if you sort it by alphabetically and it like A to J, it will do K through Z on the rest of the site - sorry. K to Z on the rest of the page.

Hannah Corey: Awesome. We have another question on sorting. Will it issue a new query to the database or store at the presentation tier level?

Heather James: I think that - that’s actually a good question. I don’t know the answer to that. I think if you sorted it - I actually don’t know the answer to that question. That’s a good question. I will find out for you next week.

Hannah Corey: Awesome. The next question is can we get a quick look at the generated SQL for relationships?

Heather James: Yes. Okay. Well, if you are a database programmer, you probably have already kind of you’re scratching your head and you’re wondering “What is that?” It's a join. So here we have the join, we’re seeing - it’s very small and very pale. So this is exactly what you would have done if you were writing your query. Is that kind of what you expected to see? I assume so. I guess I won’t get the answer right now.

Hannah Corey: Yes. That’s exactly what they wanted to see. Thank you.

Heather James: Yes. If you’re following along and you’re working on your Views and you can’t see your query settings, remember you can go to Views, settings and you can actually show the SQL query in the live preview. We can talk a little bit about some of those performance things next week too.

Hannah Corey: Awesome. Okay. We have a couple more questions. How can we assess how efficient those joins required by relationship are?

Heather James: I think that’s when looking at the performance statistics will come in. I think once - tune in next week. You’ll see how you can actually export your Views to code. Once you’ve done that, you’ll be able to tweak any of those queries yourself and improve them. You can sort of, in a way, could say let Views be something that you and your team prototype with, and then you may use it sort of as jumping off point to maintain more optimized Views queries.

Hannah Corey: Great. The next question is can you please give us a sense of what kind of things we should not try to do with Views?

Heather James: Yes. I actually - I was going to talk about that with this view of all content here I made. I think that Views - I’m pretty sure this has been hammered through very clearly but seeing this earliest version of Views, the default setting was to show all content and actually - instead of showing fields - I’m just going to edit this one here. Instead of showing fields, it actually would show the full node. So, for example, here, like the full content. So what that meant was if you had a view such as this which shows all content and also uses Ajax, you’re basically trying to pull all the content from your entire site in all at once. So this is sort of - this was basically always the fear of - for example, when we did Drupal Gardens at Acquia, one of the fears when they added - before they added Views was someone could make a query that could cripple their whole website and slow it down.

So if you sort of think of Views as limiting a selection and you’re filtering to limit what content you’re showing, you’re not trying to just vomit out everything from your site, then you’re pretty safe. There’s probably a limit as well. I spoke about this last week. When you’re adding a lot of displays, additional displays are actually loaded - when you view, for example - on my own website, you look at the Canadian list, you are also getting on any content that’s loaded for the other displays as well. So you might think just that. If you’re using displays, make sure there’s a lot of similar content between them. Caching is going to help there too.

Hannah Corey: All right. Awesome. The last question is can you filter the visibility of the block view by content type rather than by path patterns?

Heather James: You can, absolutely. I mean, in my case it wasn’t going to work because I was trying to change the users of - showed on the user profile but you actually totally do that. So I'm going to go this level block, for example. Instead of showing it on every page, I’m only going to show it by specific content types like I only want to show it on courses and recipes. It’s kind of the only place that levels is relevant too, for example. So I’ll save that and my level block no longer shows up here but if I click through to my course, for example, I’ll see my level blocks show up. Well, it’s actually interesting. This here is a taxonomy view when I went to the beginner list. This is just - excuse me - a list from the taxonomy. It automatically comes with the taxonomy module that’s core in Drupal. So what’s interesting is you might think “Well, I don’t like the way this looks. Maybe I want to change that with Views.” If you go to structure Views - it’s one thing I intended to show you. You can actually get an overwrite of taxonomy with this Views template that’s actually available to you. So it actually overwrites taxonomy. There’s also one for the tracker. There is one for - there’s an automatic one for archive. So definitely checkout some of those Views defaults. It might give you some more help too on using some advanced functionality in Views.

Hannah Corey: All right. Great. I think that’s it for questions. Thank you everyone for attending and thank you so much, Heather, for this great training presentation. Again, the slides and recording will be posted to the Acquia.com website in the next 48 hours. Please definitely signup for next week’s training course with Heather. Heather, do you want to end with anything?

Heather James: No. Thank you so much. I’m seeing this, Hannah. It’s a huge help. I’m looking forward. If people come next week and have questions as well, if they’ve prepared things and - I think, Hannah, you’ll be able to give the questions from this week and I can follow up on anything. There is one question I definitely will follow up on.

Hannah Corey: Yes. Definitely. All right. Great. Thanks everyone.

The Practical Guide to Selecting a Web CMS for State and Local Government [May 2, 2013]

Views Mini-Course, Part I: An Introduction to Views [May 1, 2013]

Click to see video transcript

Moderator: Views Mini-Course Part 1 – An Introduction to Views with Heather James who is the manager of training here at Acquia. We are very excited to have Heather on the line.

Heather James: …the training program at Acquia was established in 2010 and just last year, we trained over 3,000 people, so we get a lot of people in the door who are brand new to Drupal. We maintain our own course materials so they’re continuously updated, and that keeps us pretty busy.

The training is actually run by our training partners and those folks are experienced developers and they actually enjoy getting away from behind the computer and helping other people, so you’d actually find the events are quite fun and you get a lot of insight into real-life kind of Drupal problems and solutions.

We have a lot of tailored courses available and I’m happy to talk with you at any time about setting up training for your team, so please contact me if you need some advice.

So you’ve landed on the very first class which is our first mini course, which is an introduction to Views, and we will have soon a Drupal for Project Managers mini-course that will be a four-part course coming in May. We put these together because we thought that there were still lots of people who – and even though there are a lot of free stuff out there, we wanted to contribute and make some more training available for you guys.

In this mini-course, you’re going to find out in these three weeks how to expose data across your site, create lists of content, users, and terms; and format it as tables, lists, galleries, slideshows; and that’s really what Views does. Today, we’re just going to start with the very basics. We’re going to start with just how Views works and what it does, and give you a general orientation and terminology of just so you’d kind of know enough basically to be dangerous, at least in the next week.

In order to get most out of today’s session, you’ll need to already understand how to add content to Drupal, how to customize content types, what modules are, and how to install and configure modules.

You might find yourself somewhere on this spectrum. I actually was sort of surprised that you might find people like this little orange dot here, someone who has actually got some experience with Drupal but really doesn’t know what Views is or is aware of Views but hasn’t actually felt them or made any use of them. I expected everyone to be like this blue dot. If you know Views and you’re experienced with Drupal, you probably know a lot about Views, but what I was surprised to find is on a lot of client sites where they’re building websites and not making any use of Views at all, and that’s why I wanted to run this mini-course.

We’re going to dig in now and first thing we’re going to do is address a kind of misconception, we could say. We’re really I guess brainwashed by this metaphor of manila folders and files and manila folders, and we sort of still think that way to the point when you’re even developing your own website, you may be thinking, “I’ve got a mental sitemap with pages and they fit in folders.” In fact, some or many actually - CMSs actually work this way so you may be familiar with other CMSs where you’d want to add a section on your site, so you add a folder and then you add in pages within that folder.

The problem is this isn’t just a mental hurdle. It also causes logistical problems if your CMS does work that way. Say for example, you want to add news headlines showing up in the sidebar of your contact page, so you’d have to what – maybe every time a news item was added, you’d have to copy the text, put a link, and update the contact page or update it all across the site wherever it appeared. Believe it or not, there’s a lot of people still even using Drupal that way and you don’t have to.

What we’re going to do right now is think of Drupal as holding data so not everything you’re going to see on our Drupal site is content per se but everything is data. Views is going to help us expose those data across the site, so you can think of these in different groups.

Now, I just thought it would be good if we got our hands dirty first of all. I’m going to do a very quick demo and kind of a magic trick and just show you how Views works. I promise I will go into it in much more detail afterwards.

The first thing we’re going to do is look at what Drupal does out of the box for listing content, and then we’ll see how we’re going to override that and we’ll see how to make a new view listing content type.

I’m going to bring you over to my Delicious Drupal site here. Here, I’m logged in as the User 1 or the Administrator so I see all the various controls available. Here’s a list of content on the site. We call this like the “river of content” which is okay. If I go over to Site Configuration, Site Information, I can see that I could change the amount of posts on the front page and I could even change the path, but that’s pretty much all I can do. The only other option I have is to go to Structure, Content Types. Say for example, with a specific content type like the fan art or cooking website, we don’t want recipes to show up on the front page. So I could change the default option that it doesn’t show up on the front page, and so I could limit that by all the various content types but still it’s quite limited in what I can do.

What I’d like to do on my Delicious Drupal Site is have a list of news items or news articles, so I’ll show you how to do that. Go to Structure, Views; of course, with the Views module enabled already. So we’ll go to Structure, Views, Add new view, and I would call it News Articles. Show in Content, so I mentioned before, we’ve got lots of different data here. We’re going to select Content in this case; of type, Article, so I’m limiting how much I’m going to show. I will create a page, here we go. I can even customize this path to make it shorter or change it any way I like. I’m going to keep the Default options. This is where you can see you can change your formatting and to keep it as Teasers, and that’s pretty much very similar to what’s on the front page and I can change the number of items to display.

I’m just going to save the options as we set them up in that wizard there, Save & Exit, and here we see a news page. Okay, fantastic. We’ve only got news articles now. We’re not getting everything else but if I go back to my home page, of course, it’s not set to my home page yet so I have to go back to Site Information and make my Default front page the news path that I just created.

Now, this is a little bit of magic hand-waving I’m doing right now. I am going through this a little bit quickly. I’m going to ask Hannah. If anyone has questions, Hannah can message me on Jabber and I’ll be able to see her questions if I’m going too quickly. I just want you to know that I will be covering this in more detail.

Here we go. We’ve created a view and it has got just the news. So hopefully at this stage now, what you know is that Views can allow you to basically limit your display of content. Let me go back to the presentation now. Now, there’s a potentially confusing problem. You may have realized that when we’re displaying content, we chose Teasers. Those are called View mode in Drupal and that has really nothing to do with Views, so another option which I’ll show you soon is to select Fields and then you can get field specific control.

At least at this stage, if what you understand so far about Views is that it’s a query builder, then we’re goaled in. We’re right where we need to be. We’re going to take a step back now and let me give you a little understanding of why we really have Views.

I love this website here. This is the Jane Pickens Theatre site. When we look at the front page – or the Coming Attractions Page, I should say – we may think, “Oh, okay. Well, we’re looking at a page of all of the content on this site and maybe this page is a piece of content where I can go in and edit the title of that coming attraction.” In terms of what Drupal thinks about this content, it’s only this piece here so we’re looking at one item of content or actually it’s called a node in Drupal, and that excludes anything in the sidebar, the header, the footer. This is just one entry in the content table as one piece of content. When we see something like a landing page like this, what you’re actually seeing is a collection of lots of different content from across the site. In the middle here, we see a slideshow so it’s just showing us things which have somehow been marked Featured, and then we’re seeing at the bottom, Coming Attractions like a gallery of movie posters and music posters.

This may be very different from how you’re thinking of how you approach developing your own sites if you’re new to Drupal. Now, perhaps your process and your workflow starts at Fireworks and you make your perfect markup and then you go to make your perfect markup and you got everything working just fine. Maybe in the old days, when you were doing database connections and combining HTML with your query results, you had to write this kind of messy code yourself. Things have gotten a bit better. We’ve got some great CMSs out there.

Here’s an example of ExpressionEngine which is like a tag-based templating system that has a query that we can actually alter and change. For example, say give us some information about the users. My question is what happens in the case that a client wants to change some of the logic or change what gets listed? They’re going to have to be calling you, right? I think it’s fine definitely if your business is keeping people’s websites updated and changing them, then you’re happy but if you work with a larger team of people, you may find that Views is going to be much easier to work with that will allow your colleagues to go and change the queries and update things or even create their own Views.

In fact, Views itself was actually developed at Sony by Earl Miles or merlinofchaos, and it has become so popular in fact that it has been included in Drupal 8. I don’t know if you can see the text here is quite small but one of the things that was found in Drupal 8 is that basic default front page was replaced with Views, so even that activity that I just showed you, replacing your front page with Views, is already included in Drupal 8.

So let’s say you’re brand new to Drupal and this happens a lot in a situation where you might want to create events. You probably would go directly to Drupal.org and you might be looking, for example, for a module that will allow you to have easy date selection, sidebar block showing like a little calendar or something like that, and you look for the event module. In Drupal 5 or 6, that’s exactly what you would’ve found but now with Drupal 7, we’re sort of pushing over into more generic and flexible solutions. So it’s actually a funny thing because you’ll actually be using less modules altogether. You have to use more modules to get the event – obviously, you use more modules to get this event functionality but once you have Views installed and the date modules, you can use them in lots of different ways.

You have a lot more control as well so instead of in the event module if you want to change, for example, how the data entry was, you have to write custom code yourself whereas with the date modules, you can create a field and control how the input is – if ever received I guess you could say. You can also have options for formatting how it displays so with Views, for example, you have the option of display formats or templates that create these calendars, the Full Calendar or the Calendar module. I hope that gives you a sense of really want makes Drupal a little bit different. I like to call this the “big fancy middle man” where Drupal allows you to control and configure display and layout. It makes it very different from other systems as you saw with ExpressionEngine or maybe WordPress.

At Acquia, we really believe that you’re going to get a better quality site that’s easier to maintain through more configuration, more site building, and less custom code. In fact, this just results from a survey done in 2011 of Drupal agency executives and they said that’s pretty much what they were looking at. It’s about 80% of their development project was done with site building and configuration and overall, that has less security risks, it’s easier to maintain, and I think you’re going to find it much easier to manage.

At this point, as long as you understand I guess that the CMS supposedly makes it easy, obviously, for a lay person to update content on the site without a developer, it’s Drupal taking it one step further and putting those developer tools within the reach of other people on your team. In fact, with the training we provide, we often find it’s a matter of change management because people have to change even the way they communicate within their development team so you may find that someone else in your team who is involved in user experience is able to now create a view and get involved in actually creating workable prototypes of your site.

We’re going to take a second to find your way around the Views. I just wanted to ask really quick - did anyone have any questions so far? I’m going to see. This is my first time actually doing the webinar so I’m sorry about any problems I’m having.

Moderator: We have one question come in. Will you be explaining one of the Views you’ve used versus one that’s not?

Heather James: That’s a really good question. Yes, definitely. I think that in general, you want to be using Views especially for listing content on your site. I’m sorry, I’m just getting a little dazzled by the interface here on WebEx. If you’re going to be listing content on your site or making any lists of any data on your site, you want to be using Views basically. There are situations where if you have a site with a large volume of content or large volume of comments, for example, you will probably want to export your queries and optimize them and make them a little bit more fine-tuned but other than that, Views would begin, would start as a really great prototyping tool, for example, so I hope that makes sense.

Moderator: We have one more come in.

Heather James: Sure.

Moderator: Everyone has events. Does everyone have to build event content types or views? Is there a best practice?

Heather James: Yes. Actually, I did an events webinar a few months ago and because something like events we’ve done so frequently, there are people sharing modules that extend what Views can do. For example, write your calendar display, there are some great modules that help you get control over that. In terms of events management though, it’s actually sometimes you may be wanting to handle commerce, so you might start with something like Drupal Commerce to handle the payment or registration, or you might be using another service such as Eventbrite which handles your registration externally, and there are modules for that as well. I hate to say it depends but let’s see. I think it does actually. I hope that helps. We can get you the link to the – or you can look on our site for the events webinar which I think could give you a sense of how to configure your own event content type.

I am going to dig right into the Views UI and help you find your way around. I did a little magic trick before and we used the Views Wizard. The Views Wizard shows up when you first create a view and it has got some very basic functionality available but like any good wizard, I want you to know that it does disappear and that’s extremely confusing for someone who’s new to Views. I’ve had this time and again. People go back to edit the view and they expect to be able to get back to this wizard. It won’t happen.

What you will see the next time you edit your view or continue on to Save & Edit view is the regular Views editor interface. Admittedly, there are a lot of options here so it can be a little dizzying, but we’re going to simplify the whole interface. If we just think about two questions, we’re first of all going to limit what we’re displaying so you’re going to focus on the sections of what you select and filter. Next, you’ll be thinking about how to format and display that so there’s a few sections I’m going to talk to you about to show you how you can get control over what it looks like.

Next week for the second session, we’re going to go into all of these in a lot more detail but just for right now, I just want to give you an overview. The first thing you’re doing is you saw me do when I created that articles list is you’re choosing your base table. If you already understand how databases work, you probably have a sense of, “Okay. I’m actually going to run a query on a specific set of data in my database.” Once you do that, you cannot change it later.

You can, however, use relationships to get data from another table and if this sounds like gobbledygook, I’ll give you an example. You may have a list of content and then you want to also show the author or maybe something about the author, maybe a picture or something like that. You can use relationship to get more information about some related data.

The next thing you’re going to do is somehow to filter a limit, so you don’t want to just cripple your site by listing all the content and everything. You’re going to either like limit by which author you have or maybe you want to limit by a specific content type. After you do that, you’re going to somehow select – you can select the View mode as I showed you before with like the teaser or you can select Fields. You’ll probably most likely be selecting Fields and you can even change and arrange how they layout.

The next thing you’ll do is select a format. So you’ve seen a lot of different formatting options here. You’ll notice I put in a map. That would actually be done with another module that will plot your coordinates, for example, on a map. There are some great tools. There’s not just these. There are slide shows and there’s a lot of great other modules you can try out and we’ll be talking about those as well next week.

I’d like to point out as well, you can configure the formatting that is output. Let’s say you have a field like the title. You can change what header that will be output as. You can even rewrite the output. You get a lot of control I think that people miss when they’re creating their Views. In this example, it’s probably hard for you to see on the small screen but you’ll see you can add a level field then exclude it from display, and it becomes then a token. On the right, what I’m showing you is that you can add it as a CSS class. It just gives you a lot more flexibility of how you rewrite the output of your view.

You then choose the type of display. You probably do this in an earlier step but it makes sense at this point to think of you can either output page displays or block displays. There are RSS feeds. There are a lot of other displays that become available as well when you add contributed modules.

Just to give you a sense of like the output, for example, let’s say I created this table of recipes. If you can see I’m inspecting the code there, you can see that the level or intermediate, for example, became a class on that table data cell, so that will give you some ability in CSS. I can make that color a specific color or something like that.

So just to recap, we’re going to choose what to query. We’re going to limit the selection. We’re going to select what we’re going to display, whether it’s Fields or View modes. Then we’re going to configure the formatting and then we’ll choose the displays. Let’s go and do that. We’re going to do another demo. This is the second demo. Hopefully, everything works out.

We’ll be adding a block display to our news list. We’ll choose some fields. We’ll put it in the sidebar, and then we’ll change the fields and change the display and see how it works. So let’s get right to it.

Here I am in my news article view here. A handy way to get to edit the view is to go here on the little gear on a contextual link. I would like to add a sidebar block so I’m going to add a display. Now, I’ve got a block. Well, I’m going to give this display a name because I could end up with a lot of - News article list, I can put it that way, and then to put a lot of displays possibly. Probably for best practice, I should go here and rename this one – Front page news teasers. Do whatever, you could put some information like that, for example.

Here, we’re going to edit this block, News article list, and I’m going to change the format. I’m going to get a preview, first of all, like I don’t want all of this content showing up in my sidebar. That would not look good. I’m going to change the format from content. Oh, sorry. For selecting what’s displaying, we’ve already selected what we’re displaying just to point out that we’re already displaying the content type article. We’ve got something we’ve already selected.

So we’re going to change from Content to Fields, apply it in there and it should throw up an error. Fantastic. Oh, it should throw up an error anyway. It automatically added the field title. Oh, that’s fantastic. Okay. We’re going to add now I think a date will be good for the news list. Add a field, add a date, Content: Date, okay. I won’t need a label. You can change the format so just like a nice short date, Apply, and here we can see it’s not displaying. Fantastic. I love doing live demos and not realizing what I’m doing. Yes, I actually picked my date fields. This is good. Actually, it’s great to learn while someone else makes an error. I picked the wrong date. I picked the date field instead of the date the content was posted. That’s important. You could also choose by Updated date if you chose news, for example.

Let’s see if that worked. I’ll deselect Create a label and choose Short Format. I hope you’re all enjoying my live demo [laughter]. What an opportunity for comedy. So here we get the title and the date, so that’s okay. It’s coming along all right, but I’m going to go and change the format now because I’d like these to show up in a bulleted list. I’m going to change from an unformatted list to an HTML list and just see how this goes. Here we go, fantastic. We’re getting a bulleted list now that looks a little bit better. However, what I’d like to do is have the fields – I’d like to have the fields sort of running next to each other. I want them to show up in line, so go to the Fields Setting and select these fields to be in line. All right, so that’s a lot more – well, it’s a bit more close to what I was planning on doing.

I don’t want a pager at all on my news item. Excuse me, I don’t want a pager on my block. That’s just not going to look right, so I’m going to change it to - for This block, I will say Items to display, display 5, Offset, and – oh, sorry. Use pager. I’ll just click here, just Display a specified number of items. Yes. Items to display 5, sorry. So here we go, a list of news items with the date. It’s getting a little bit closer. I can already see I’ve made the error I was going to try not to make. Let’s see what happens. I added the block and I changed the options there. What I also overrode what happened on my front page, so it ended up that when I added the display, you’ll notice here I’m going to go Show Fields for example. I changed it for All displays instead of This page (override). That ended up overriding my default, so I have to go back and undo everything I’ve just done.

Let me go back to Fields, change to Content, and change to Teaser, Apply (all displays). That looks a little bit better and if I go back to my block, it should look… I hope you guys thought that was funny. Sorry, This block (override). Okay, get our Inline Fields.

All right, so here we go. We’ve got the front page news. Hopefully you can see it’s okay, and we’ve got the teaser showing up and then in my block, I get the News article list and we’re seeing just the bulleted list. Okay.

So now that I’ve created this block display, it will be available to me in Structure, Blocks, and it will show up down towards the bottom, hopefully the list, and we see the View News articles: News article list and I’ll pop it into the sidebar. Put it over here, it shows at the top. Okay, so that should show up in my sidebar second here, above my search form, back home and voila! I’m getting my title and my date.

At this stage, you should understand we’ve got displays. We’ve got the news display and we have the block display showing up, and you also saw what happened when I wasn’t careful enough that you end up actually overriding your displays. So I suppose you can’t put too fine a point on it. You just have to be careful when you’re selecting specific displays in the editing options. It’s something that generally tricks people up in the early stages, and as well best practices to name your displays and that helps you keep track. As you see, when you saw the block listing, that’s the spot what I was looking for.

Let’s recap what we’ve done. First, we selected and filtered with the news articles. We selected specific fields; in that case, we chose a title and a date. Then we change the format so we changed it to be a list. You saw me go back and forth between a list or the view mode, a teaser, and then we chose a display. We had pages and blocks.

Now, that you’ve seen the two demos, so where do you find yourself now? Do you feel like you know a little bit more what Views is? You’re on the – has your yellow or your orange dot sort of moved up a little bit? I’d like to hear what questions people have at this stage.

Moderator: We had one question come in that says, “I’m sorry if I missed this but are we able to add RSS feeds?”

Heather James: Yes, that’s a good question. Let’s look at how to do that. I’m going to go back to my environment here and let’s say, for example, I’ve got my news articles. What we’d like to do is especially on the front page, we’d like to customize it so the front page RSS feed only shows news items. Go back and edit. Before I make the change, you might be already thinking how could I add a list of RSS items to a view? So based on what you know so far, you get the idea that you can add displays. Right across the top here, we’ll click Add a display as a Feed. The Feed options are a little bit different so we don’t have the options, for example, to utilize Fields. It’s a little bit limited, but it’s just automatically formats your RSS feed as you need.

Let’s set a path here, so we’re going to say news stories. We’ll get an output and this is going to give me a preview what the RSS feed will look like generally. There we go, cool, so that’s our display. Does that explain it or no, maybe not yet because I haven’t saved it? Yes. Click Save. The Save button is at the top in Views as well so hopefully you won’t have any problems with that. I’ve actually seen plenty of times where people are working away on their view happily and then they’ll end up not saving what they’ve done. A sad day then. I should see a news – ah, fantastic. I actually will create this as an attachment, in fact. Maybe this would look better.

Another display we can do is an attachment. I’m going to just change one thing on the front page, Front page news first of all. It’s to actually change from five items to like two items, first of all, so we’re only getting two news items up at the top. The last display I’ll add is this front page sub-list, old news we’ll call it.

In the Front page old news, I’m going to change it so we have – I’ll show you the front page now. We’ll see the – what we’re going to do is have two news items and at the bottom, we’ll have like a bulleted list. Maybe I should show you guys something. Okay. I could close either views. So we’ll show you a list of This attachment, change it to HTML list. Instead of Content, we’ll change to Fields and let’s just show the title and save. I’ll remove the updated date from this list. So here’s a list of the other news items and instead of displaying 10 items, we’ll offset to three so we won’t display. There’s just three items that we’re only getting, a few of the options here. We’ll position this attachment After and attach it to the Front page news.

This is the last display to show you. I guess I was going to save this till next week but we didn’t have a lot, so I guess this went a lot quicker than I thought. Let’s look at after you save this, how it appears on the front page. So we see the news articles and there are two items showing up at the top and then the remaining news articles. It would show 10 if I had more news articles on this demo site, but that’s really the last type of display that’s available by default in Views.

Are there any other questions?

Moderator: Yes. We had a couple more come in. What theme are you using?

Heather James: This is just regular old Bartik. This is the default theme that comes with Drupal 7 and I’ve only just changed the logo. Awesome.

Moderator: Okay. The next question is how do you add a lightbox from each image that a view returns so a larger size image can be viewed in a pop-up window?

Heather James: A really good module for that is Shadowbox. I recommend it because it actually provides you – that’s a really good question. I’ll be able to show you next week so I’ll be showing you modules that extend what we usually do. What this allows you to do is it provides you a different display mode so you may think of – let’s say for news articles, for example, let’s go back to our Front page news and I’m going to mess around with this a little bit more just really quick. I’m going to change the Content to Fields for This page. I won’t make the same mistake twice, of course, and apply to this display. We’ve got title and an updated date. We’re going to add an image which is appearing in my node article there. You’ll see here we’ve got a Formatter, Image formatter and we’ve got the Image style, Medium, for example, and link to Content or File.

What Shadowbox will actually give you is another formatter option. There’s a number of modules that do something quite similar, but it will basically give you a formatter so it will have a display in a modal window. A lot of times these contributed modules are just extending what Views can do because it doesn’t have to do everything. It’s just things are offered from network to Views. I hope that’s clear.

Just see here, this is where we’ve done enough so far with messing around with the front page. Page display, this looks kind of horrible. So apply this, just change into an Unformatted list here and just to prove the point, I sort of showed you before you can change the style settings, even rewrite the output, for example. I’m going to change this to like heading three, for example. The image – oh, remove label. I’m just going to be demo-ing away here. I have a few more notes to add to the very end of this presentation here but if you have questions, feel free to ask.

What we’ve done so far, I guess, is you’ve got my idea that with Views, you get a lot of control over what you can display and how it displays. Oh, it’s fantastic. I’m so impressed that I keep on forgetting to do this. I meant to make the first time I did this, I didn’t mean to make a mistake. I thought I was being clever but yes, I’ve got time for questions. Sure.

Moderator: Okay, great. The next question is can you explain the difference between Views and blocks?

Heather James: Absolutely. What you see with Views is that you can create blocks so I’m going to rename this to be News block, for example. I could actually create multiple blocks with Views. I could add another block based on the same query of news articles, for example. Views creates blocks and then blocks are things you place onto the website, so we’ve got Structure, Blocks, and one of the things that has been output – let me just save this. One of the things in output is my News articles, News block. That was actually created by Views. There’s a lot of different blocks just by default. Drupal comes, for example, with a list of recent comments so I’ll just show you that default block. Let me put that up in the Sidebar Second under the Views block there. So blocks can be upped by a lot of different modules and you get some control over where they display. Does that make sense? Views creates blocks.

Moderator: Yes, great. The next question is will you be explaining how to export the queries, optimize them, and re-import them?

Heather James: Yes. Actually, that’s exactly what we’ll be doing in the third part of this. If some of this is a little basic for you, you already know a bit about Views, in the third part of this, we’ll be taking and exporting everything. You’ll be able to see how to export everything you’ve created and save it as a module. Let me just show you. I want to go to Structure, Views. You’ll notice, for example, with this News articles view, I can go ahead and just delete this, which is kind of scary. I can go and edit it and all the changes I’ve made and all that work I did could get lost instantly. What you’d be able to do with the module is have a list of content and I’ll show you one that I actually have, the one I did at a Drupal camp. This one here is not deletable because it’s actually saved in code, so there’s in database overriding code but I can also revert it and it will revert back to what’s saved in my module. So it’s a safe way to back up your Views.

The query that actually gets created is sort of helpful. I think if you want to look at the query itself – sorry, I have to go back to my settings. Go to your Advanced settings here and you can show the SQL query right when you’re looking at it. You can also show some of the performance and how it’s running. Let’s just look at the SQL query for now.

Okay. There you go. Here, you’ll see – if you already are a person who knows how to write database queries, you can get your insight here. Oh, my worst fears have come true. My unprofessional cat has showed up for this webinar. I’m sorry about that.

I’m going to just finish up with some final notes. I know that you guys are giving your time over to this and I just wanted to give you an idea of what I’d like to do over next week. If you’re brand new to Views, I’d like you to go ahead. Based on what you’ve seen so far, create a view yourself so this would be listing of specific content type or maybe all the terms on your site, and create a page display and a block display and then place the block in the sidebar of your site, just the same way we did.

I actually created a tutorial which has just four- or five-minute videos, 20 minutes, so I go through these steps very clearly and you’ll be able to complete that activity. When you show up next week, you can ask me questions more specific to the problems you run into.

If you are a little more advanced as well and you want to learn more, there is a webinar available that was just done yesterday with my training partner, Suzanne Kennedy from Evolving Web, as well as there’s a Mastering Views course actually happening at DrupalCon, so if you’re going to be in Portland, that’s a really great opportunity to get a lot of detailed help with Views.

Then we’ve got some Views tutorials so I mentioned my quick one there. There’s also Drupalize.me that has a great series. It’s not free. There are some free ones there. There’s also a free 10-part series with the Toronto Web Developer, Pete.

That should give you enough help so that by the next time we meet, hopefully you’ll come to the next one on May 8th. We’ll give you a lot more detail on how to build flexible views. Please do sign up for that one as well.

I put up all the notes from this class and all those links. I figured it was probably quite a lot of information. I’ve actually put them up on our blog and so you’ll be able to get access to those tutorials.

Of course, please do come and check out our events. You can meet me at Dublin Drupal Dev Days as well if you want to talk more about Views and configuration. I’m just going to show you that blog post there.

We have about a few more minutes. I think we’re closing soon, but are there any other final questions?

Moderator: Yes. There are a couple more questions that came in. Is there any limitation on the number of blocks we can create in Drupal? Can we create more than 256 blocks?

Heather James: That’s a really good question. You probably – what’s interesting actually about the various displays, you could keep on adding displays to this view and if you think of it, it’s really just variations on the same query. If we’re querying very similar content, it makes sense to just simply add a display. If you’re at the point where you’re adding 250 blocks, you probably have a different need, so I’m going to give you just a hint of how this is done.

Let’s say we had a news page or we have a news article obviously here. Or actually I may have something already created. Let’s look at one I did earlier. I look at the cooking, for example, cooking recipe here. We’re looking at this baking recipe. What we want to show are related recipes and we don’t want to be creating a new view for every single recipe on this site. I’m just going to click on – I’m trying to find one that actually has one. Let me get the baking recipe, or maybe not. Okay. Let me hold on a second. I could get something that’s related based on taxonomy terms. Right. We’ll be showing you this on the next one, but just let me try and do a very quick explanation.

Let’s say you have this recipe here for beginners and you wanted to show in the sidebar other beginner recipes. Well, you wouldn’t want to have to create all of those different blocks for all of those different levels. What you’d actually use are contextual filters, so what it will allow us to do is create a block. For example, we can create a view and I’m just going to quickly see if I can do it and get under the Related levels. Show Content of type Recipes. You don’t want to create a page. We’ll create a block, and we’ll just make HTML list and I’ll Continue & Edit. I will do this in a lot more detail next week, but what we’ll be adding are Contextual Filters. You’d probably do something like this where you will say, “Show me content that’s related by level.” They’ll take the taxonomy term. There’s a lot of magic that goes on here but hopefully it will give you a sense that you could relate content by level. If my demo works out okay, everything will be fine.

The tutorials, by the way, that I’ve linked to you here, there is actually a tutorial specifically on how to do this, so it looks like we’re going to run out of time anyway. Let’s say, for example, we had the setup. Let me see here. I’m going to display this content of title, okay, that’s fine. I’ll save this. Structure, Blocks, and I’m looking for my recipes block I just created, related recipes. Oh, I already had related recipes. Related levels, there we go. Sidebar Second, put it up to the top, and save it.

We’ll go back to our recipes page, show a specific recipe and – sorry. Someone who has done live demos before is laughing at me right now. So we’ve got – oh, that’s not even the related recipe, sorry. I’m sorry [laughter]. I’m looking at the wrong view. Oh, can we cancel this? I’m sorry about the demo. I’ll show you this next week and I’ve actually created a step-by-step instruction about this. Let’s just say if you’re going to create 250 blocks, you probably need to choose Contextual Filters. I hope that was a good enough answer.

The other problem with it is if you are creating views that have a lot of different content, you don’t want to be adding extra displays because you’re just going to be overriding a lot. Once you start adding, say, more displays instead across here, it’s just becoming unwieldy, difficult to maintain and manage. You’re not getting any benefits.

The other thing is if you have a lot of data being pulled into your view, like if you have a lot of different fields and you’re doing relationships and joins, for each one of those displays, all that content gets loaded, so that’s something to consider. You really only want to use multiple displays when a content that’s being selected is quite similar.

I will talk to you next week about caching your queries to make them a lot faster and what effect that has on your site as well. Are there any other questions?

Moderator: Yes. We had a few more. The next question is what is the difference between one view with many displays versus many displays? When do you use a new view versus a display?

Heather James: Yes. I hope that what I’ve just said there sort of explains it. The displays are just to help you create similar lists of content so I actually was going to show you on our upcoming training site, for example. We have a list of European, global, or Canadian, U.S.-only events. If we actually looked at them, we have these individual lists of content. They’re actually quite similar across all the various events. They look exactly the same. They got the same format and the only thing we’re changing is this information that’s coming to the URL here. Those are multiple displays in the same view because the content is very similar and the only thing that’s changing is this variable of the filter criteria of the location. In that sense, we’re getting a benefit from using multiple displays. This just happens in Drupal 6 but I hope that it’s clear from what I said.

Like I said, if you keep on adding multiple displays and you added more data through making a relationship, as you’ll see next week, the pulling in things from another table, all that stuff is loaded for each one of the displays.

Moderator: All right. Thanks so much, Heather. Again, the recording and the slides will be posted at Acquia.com website in the next 48 hours. Heather, do you want to end with anything?

Heather James: Yes. Thanks everyone who showed up. I‘m really sorry that I had a few hiccups myself. It’s my first webinar so I really appreciate you sticking – it’s my first webinar in a long time, I should say, so I appreciate you sticking with it.

I’m going to – hopefully, if you got any questions through the week, we’ll be able to get them answered for you. I’m hoping that you’ll give it a try this week and come in with questions so we can talk about what kind of trouble you ran into as well.

Moderator: Great. Thanks so much.

- End of Recording -

Tips and Tricks for Getting the Most Out of Views [April 30, 2013]

Click to see video transcript

Female: Today’s webinar is Tips and Tricks for Getting the Most Out of Views, with guest speaker is Suzanne Kennedy, who is the co-founder and front-end lead at Evolving Web. We’re very excited to have Suzanne on the call today, and I’m Hannah Corey and I’m a marketing specialist here at Acquia.

Suzanne Kennedy: Hi, My name is Suzanne Kennedy and I’m going to be presenting today on Views. We’ll be covering some tips and tricks on how to you use Views. I’m assuming a lot of you already have a lot of knowledge about Drupal and want to learn more about how to build more effective websites in Drupal. Just trying to get to my first slide here.

Okay, so as Hannah mentioned my name is Suzanne Kennedy. I worked at Evolving Web and my role at Evolving Web is as a trainer and also a themer and site builder. I do a lot of the work taking care of the front-end of the Drupal sites that we build.

I’m just going to do a quick introduction to Views. If you’re already familiar with Views, this will be kind of a recap but I just want us to go over some of the key concepts. When you start off with a Drupal site and you’re using Drupal core, you have a lot of content management features taken care for you. So you already have content in your site and then you can have users and a set of taxonomy terms and things like comments, and that gives you a lot of individual pieces of content. So the role of Views in a Drupal site is really bring all that content together and organize it on your site so that might in the form of lists of content that you would find in different places on your site. So if you go to a certain page, you might see a list of articles.

A View consists of a lot configuration but the most key pieces of configuration are the fields that show up in your Views so the actual content that gets displayed and then also, you can also sort and filter what content your displaying. So you can select only to display certain types of content in your list and you can choose to sort that content in a certain way.

The basics of configuring the View consist of a bunch of steps but for any of View, it’ll consist of choosing what you want to list. So what type of content you want to pull out of the database whether it is pieces of content like nodes, users, taxonomy terms and then you can add filters and sorts to that. So you can say, “Okay, I want to show certain types of content. I want to show articles or I want to show job postings.”

Then you can choose a format so you can decide how you want all of that content to be formatted. There are bunch of different options out of the box but the most common ones are unformatted content, which gives you a list of DIVs, a list - an HTML list with ULs and Lis - and then a table, so a basic HTML table. Then the other thing you have to choose is how you want your View to be displayed. So do you want it to display when you go to a certain URL, as the main content of a page or do you want it to show up in a block.

So the first step what to list. It’s really important when you’re in the process of making a View, it’s really important to know what you want to pull out of the database.

Adding filters and sorts. This is important because obviously showing all the content on your site is not going to be so useful to your users. You’re probably going to want to add at least some kind of filtering. Often people filter by content type if you are displaying nodes. You also probably want to make sure you’re only showing published content to your users. Then it’s also important to think about how you want to sort the content. So common sorts are things like the date the content was posted or the titles if you want to show things in alphabetical order.

There are a lot of options for how you want to format your content in Views. As I mentioned there are some built-in options but you can also extend the list of options. So I’ll be talking about today about some modules you can add to Drupal to give you more options for how you format your Views. Things like calendars and maps are other ways you can display your list of content.

One of the things you want to think about right off the bat with Views is how you want to display your list. The two main options for displays in Views are page displays and block displays, but there’s other options as well. So you can display a View as an RSS Feed and attach that to a page display. You can also create attachment displays which you can add to other Views. So displays are really important when you’re working on building a View.

To just give you an idea of the anatomy of a View, what it consist of. Most Views have a title, you can add a header which is some text that goes above the list of results and then each item in the View is called a row. The whole set of rows are often called results and at the bottom, you may have pager which lets you go to subsequent pages of results if there’s too many to fit one page.

So if you’re looking at a real live View, it might look something like this. Like a list of articles and then each row consists of either a teaser or some fields.

So the role of Views in Drupal is really as a query builder. It’s a way of telling Drupal what content you want to pull out of the database and rather than having to write sequel of statements and custom code to pull out exactly what you want, Views provides a user interface for doing pretty much the same thing.

So selecting what content you want to display and then configuring exactly how that’s going to show up on the site.

The Views Editor looks like something like this. I’m sure its familiar to a lot of you and in the presentation today, I’ll be pointing out certain parts of it that you might be less familiar with. So really the goal of this presentation is to give you some insight in to what Views can do. I’ll be showing you a lot of examples and then I’ll also be pointing to places in the configuration that you might not know about even if you are familiar with Views like check boxes that can save you a lot of time and frustration and I’ll be talking about a bunch of modules you can use to extend Views functionality.

The first thing I’m going to be talking about is how to change the markup of your View. So how to change how the content is formatted and exactly what markup is used around the fields that make up your View.

So as I mentioned there’s a lot of format options to choose from in Views and it’s important to choose the right format.

So the built-in format is listed here and the unformatted list is kind of the default that people go for but you might want to explore using some of the other ones.

So for example, if you are showing a lot of visual data, it’s ideal to use the grid format which you can use to make a table but it’s to display non-tabular data. So often content is more visual, if you have a lot of images that you want to show in a grid. It’s often used for displaying grids that show the users on your site.

Another option is HTML tables. So if you have a lot of content and you want to make it easier for users to scan the content, displaying your list as a table rather than an HTML list can be a good choice.

Another thing to think about when you’re working for a markup for your View is whether to display your list as a set of fields or as part of content.

So this is a terminology that can be a little bit particular to Views but there’s a setting in Views called the ‘rows style setting’ and this lets you switch between showing fields and showing things like teasers. So do you want to have fine-grain control over your View and be able to manipulate how each field is displayed or do you want to leave that up to the settings that you already have for View modes on your site so things like teasers.

So that option looks something like this, choosing between fields and content. With fields, you get to control exactly which fields are showing up, what order they’re showing up, and you can change the markup for each field. Whereas if you choose content then you’ll be selecting a View mode on your site so the common View modes that you would be using will be things like Teaser and the Full Node but you can add other View modes to your site as well. The advantage going with fields is that you get a lot more control over how the fields are displayed. The advantage of going with the View mode, is that you can create a teaser that really looks great for your content and then you can reuse that on multiple Views so you don’t have to re-configure it every time. So if you do go with fields, you get a lot more options. I’ll be showing you some of the other things you can do if you display fields in your View.

So one thing you can do if you’re displaying fields in your Views is that you can change the markup for each field right in the configuration. So if you have a list of articles that’s what you are showing in your View and you want the title of each article to be an H3 tag instead of span or a DIV then you can change that right in the View’s Configuration.

So when your configuring your View, you can go into the style settings and the configuration, and you can actually use exactly which HTML tag is used to wrap that field. So you don’t need to be a themer and make a custom template to make this change, you can do it right in the Views Configuration. This can be really useful if you have specific requirements for search engine optimization or if you’re trying to follow a certain standard in terms of the markup in your site.

Another thing you can do with field is you can combine multiple fields together in the same HTML markup. So if you have two fields that you want to show and you want to show them next to each other, or if you want to combine them somehow then you can actually exclude a field and add it later as part of the second field.

So for every field in the configuration, there’s a check box to exclude it from the display and then there’s another setting for each field to rewrite the results so you can add some text to the field before it’s printed out or you can actually use tokens to combine multiple fields together.

Another thing you can take advantage of when you’re displaying fields in your View is using field formatter. So you are probably familiar with field formatters when you configure content types in Drupal. You can select exactly how the field is displayed using the field formatters that the field type provides. So for example, if you’re using a link field, you’re using a link module for example, you’ll have an option to display the link as a link or as a text, a linked text. So there are different field formatters available depending on which fields you’re using.

So for example, if you’re looking at a mockup of site and it looks something like this, you’ll notice that there are social media links in there that are styled in a certain way and then you have dates listed for each result and those have a certain format as well. So being able to choose exactly how these fields are formatted is really important.

Another example of needing to format fields is if you’re displaying media in your View. So if you’re showing a View that lists a lot of videos or audio content then you want to have some way of formatting the audio file or the video file as an actual player like a video player or an audio player.

So in the field configuration, you can select which formatter you want to use and a lot of the formatters have settings as well. So you can choose to display your images as actual images and then you can choose the size to use for those images. Or in the case of the date that we saw in the examples, you’d be able to choose what date format to use.

So those options are all for how to have more control over the format interviewer field in Views but the other option is to use View modes. So the built-in View mode that you’re mostly to use in a View would be a teaser. You can control the display of the teaser through the content type configuration and then you just take advantage of that in your View and use the configuration that’s already been done on the content type UI. If you need to display your content in more than one way on your site, you might consider using View modes, and you can set up custom View modes using the display suite module.

If you want to display content in different ways on different parts of your site but you want to reuse that configuration across Views then this is really a great technique to use for that. So to take advantage of this, you have to set up your View modes using Display Suite and then choose to display the content of your site as content rather than fields. Then in the settings for that, you can choose exactly what View mode to use. So you can switch between teaser, full content and then in this case, I’ve set up a custom-made View called mini-teaser that I can use to display my content.

Another great feature of Views which is really useful is being able to add multiple displays. So you’re likely to be displaying content throughout your site in different places and you want to be listing that content in different ways depending on the context.

So for example, I may have a View that shows articles and I want to display them on an articles page but I also want to display them on the homepage on a block and maybe I want to display them on another page at the bottom of the content. So I have three contexts that I have the same View that I want to use. I want to be displaying the same content. I just want to be varying it slightly on depending on where it is showing up in the site.

You can accomplish this using multiple displays and just creating a single View. So let’s say I make an article view, I can have a display of those articles on a page and then I’m going to be associating about a path for that page but then I can also set up a couple of blocks. So I could be displaying the same content in three different ways using the same View. So in the Views UI, there’s a bar at the top that shows you all the displays you have and you can add more displays that way. Now, once you set up multiple displays there’s probably going to be some variation between them. So maybe in one display you’ll be showing certain fields and then in another display, you’ll be adding a couple of extra fields.

So Views lets you override any of the settings you have in your View or many of the settings you have in your View depending on the display. So whenever you’re choosing a setting or changing a setting you can choose whether you’re changing the setting for all the displays in your View or just the display that you’re looking at currently. So this is a way to build in to reuse the Views logic or the Views configuration that you have built across your displays but still allow for flexibility. So it still allows you to change some of the settings depending on the display.

So talking about displays, pages and blocks are the most common displays that you’ll be using but there are other displays that you can use as well and one of those is the attachment display.

Attachment displays basically let you combine multiple Views together. So let’s say I have one list of articles and then I have another display that shows articles but I actually want show one of those lists above the other. I can use an attachment display and it will let me attach one View to another display of the same View. This is really useful if you have a list of content and you want to show a featured item at the top of the list. You’ll see this a lot on new sites but I’ve seen it many different other types of sites as well. How you do this with the attachment is if you create a list of your articles say a page display and then you create an attachment display that had a slightly different configuration.

So in this case, just like I’m showing on this slide, the first one has larger image so you change the formatting of that image in the attachment and then you attach the attachment to the page display at the top.

Here’s another example on the right of the slide from the Economist.com website. The first result in the View is meant to have an image whereas the rest of the results don’t. So it’s really easy to create an attachment display and then there’s a setting to add the attachment before or after one of the other displays in your View.

Another thing that you might want to do to vary the markup in your View is to create a grouping of results to make it easier to scan results or for users to see what’s going in terms of the organization of content in your View.

So a grouping of results might look something this where you have a view that list a whole bunch of items and then you have subheadings in your View that grouped together similar items and the subheading is based on one of the fields in your View.

So in this example is a news archive and then I’m grouping the results, I’m grouping the news items based on the month in which they were published. So you can accomplish this in Views really easily by adding a field for the item you want to group by. So in this case, I’d add a field for the month in which the news was published and there’s a setting to group by any of the fields that you’ve added to your View.

So when you’re configuring the format settings for your View, there’s a grouping field setting. So you can choose to group by any of the fields you’ve added to your View. This can make it a lot easier to organize your View and organize content to make it easier for people to find what they’re looking for.

Another thing you can do with Views is create RSS feeds. So a feed is actually one of the display types and you can attach a feed display to page display. So really easy to set up RSS feeds on your site using Views.

One thing that’s really common on sites, is to have a block display that links to a page display. So you might have a list of recent news items on the homepage but you want to give users a link to a full page of results and you can do this by adding a block display and a page display on the same view.

So for example, you might have a list of upcoming courses and then you have a CL link that would link to a page of upcoming courses.

In the View Configuration, if you add a block display, there’s a link display setting which lets you choose which page you link more links to. So if you have multiple blocks and multiple pages in your single View, you can configure exactly which blocks link to which pages.

Now I’m going to move on to talk about Views configuration for filtering and sorting so ways of making your site more dynamic in terms of how your content is filtered and then also how it gets sorted and how users can interact with that on your site.

I mentioned earlier some really basic filters and sorts so filtering by content type, sorting by post date. These are things you’ll see quite a bit.

How filters and sorts work in Drupal is that you add something to filter or sort by. So you’re adding a filter criteria, for example, the published status of your content, and then you can configure that filter or that sort. So you can decide “Okay, do I want to show content that is published or content that isn’t published?” So it’s always a two-step process adding filters and sorts.

So one thing you can do that can be really useful for your content is filtering content by whether a certain field exists or not.

So let’s say you’re displaying a list of your users and this is very visual content because you want to show a profile image of each of your users; but you don’t want to show users that don’t have an image because then it kind of takes away from the visual impact of the View. You have all these placeholder user images. So one thing you can do is you can filter by whether or not a certain field exists.

So I can add filter criteria for the user image on the site and then I can configure the setting so that the result will only show if that field exist. So if user has an avatar then I’ll show the result for that user.

Another thing you can do with filters is you can expose filters to your users to let them filter the content. So rather than doing the two-step process where you add a filter and choose exactly how it’s configured, you leave that second step up to your users and give them a form where they can have some control over the view.

So for example on this site, there is a list of projects and you can search for the projects based on cities or based on states, and that configuration is left up to the users. So they can enter in whatever they want and then click apply to filter down the results. So rather than the site builder deciding exactly how the content is going to be organized, it’s left up to the user to go in and filter and find what they’re looking for.

In this example, the exposed filters are little bit more visual so they’ve been themed to look a little bit more attractive. It’s the same idea. It’s a page where you can find the project and you can filter down based on the taxonomy terms listed in the exposed filter.

So exposing a filter is really easy. In the configuration settings for the filter, there’s a check box ‘expose this filter to visitors’ to allow them to change it. So you just check that off and then you have a bit of configuration around the label for the form element that you’re setting out.

There are some modules you can use to extend exposed filters. So exposed filters are built-in to Views but there’s module called ‘better exposed filters’ which gives you some more options. Then there’s also a module called ‘views dependent filter’ and that lets you set up exposed filters that have dependencies. So maybe you’d filter by content type first and then you would have another filter that opened up depending on which content type you had selected in the first field.

So when you looked at exposed filters, they start to look a lot like search, right. You are kind of building a search UI and you can actually add an exposed filter that’s basically for search.

It’s a keyword exposed filter that you can add to your View. How you do this is you add a filter criteria for a search term and then you can configure ‘expose this filter to visitors’ like you do for any other filter that you’re adding and that effectively becomes a search field. Now, you have to have core search enabled for this to work, but as long as you have that then you can build simple search UI using Views.

So another thing you can do in terms of making your Views interactive is you can expose sorts to your users. So exposing filters is really common, exposing sorts maybe isn’t quite as common but you see it sometimes on sites that have more tabular data.

So if you’re displaying a list of content in a table and you have a heading at the top of the table listing of all the column headings, sometimes you’ll see an arrow up the top there, next to the heading and that’s a way to expose the sort to the user. So they can control how the sort is being applied. So for example, in this view the content is being sorted by when it was last updated and you can choose whether that’s an ascending sort or a descending sort. So whether it’s showing most recent changes first or the ones that are furthest in the past.

Exposing sorts is just like exposing filters, it is just a check box when you’re configuring a sort.

If you’re showing content on your site that is really date specific like you’re showing a list of events, then you should consider using the date views module to give you more flexibility in terms of how you filter and sort your results. For example, if you want to show an upcoming events View, and you want to show only the events that are taking place in the future, you can use the Date Views module to show only content where the date associated with the content is in the future.

So Date Views is part of the Date Module so it’s an extra contributed module you will have to add, and you’ll be adding it anyway if you’re creating event content on your site. Once you’ve set that up, you can add a filter based on date, and you can control exactly what content is being displayed. So like I said future content is one use case but you might have others and there’s a lot of options and flexibility there with how you filter your content by date.

So those were all the ideas about how to add more filtering and sorting to your views and now I’m going to talk about adding contextual filters and relationships. So this is kind of going the next step, getting a bit more advanced so if you haven’t been using Views for very long or you’re brand new to Views, this is just kind of a more advanced topic. Contextual filters and relationships really are what start to make your Views very powerful in terms of displaying dynamic content throughout your site and a lot of Drupal site building is dependent on these two features of Views.

So first of all contextual filters, contextual filters are a way of displaying content that gets filtered in a dynamic way. S=So rather than always filtering content the same way, the filter is dependent on where you are on your site. So if you’re looking at a certain page, one filter will be applied but if you go to a different page then the filter changes. An example of this would be a page display where you’re filtering by taxonomy terms and based on the path of the page, the taxonomy term changes. So if you go to one taxonomy term page, you’ll see content about that term but if you go to a different page, you’ll see content about the other term. There’s a built-in taxonomy term View in Drupal. You can look at that and see how that works. You just have to enable the view on your site when you install Views.

So for example if I go to a page on my website evolvingweb.ca/category/tags/Drupal – how is the content of this page being filtered? Well, /category/tags/Drupal is actually an alias because I have Pathauto on my site, as most Drupal sites do. So the actual Drupal system tasked for this page is taxonomy/term/1 and the ‘1’ part is the argument or where the contextual filter comes in to place. So my Views configuration, I don’t have a View with a path of taxonomy/term/1. In Views, it’s taxonomy/term/% and that percent sign is a placeholder for my contextual filter and the one is just the taxonomy term ID. If I want to display this page of results rather than coming up with a separate view for every taxonomy term on my site, I can make a single View that’s dynamic. That filters the content dynamically.

In the Views Configuration, it looks something like this. There’s an advanced column in the Views UI on the right, if you expand that, you’ll see where you can add a contextual filter. So I’m adding a contextual filter for a taxonomy term because that’s what I want to filter by and then I can configure it to say I want to make sure it’s a taxonomy term and then I can configure it on the second part of that interface. So that’s for pages, contextual filters where there is an argument that’s being passed through the URL to the page, and then being used to filter the content in the Views Configuration.

The other place where we see contextual filters come into play is in blocks and so I’ll give another example. Let’s say I have a lot of nodes on my site and I want to show the tags associated with the node in the sidebar rather than as part of the node content. So I have a website with some content in the main content area but then I want to break out some of that content and put it on a block somewhere else on the page maybe on a sidebar. Again, contextual filters, I want to be filtering based on the node that I’m looking at on this page but that’s going to change based on which node I’m looking at. In the block on the sidebar, the tags for the Node 1 Block in my diagram that’s going to be a View. So I’m going to use a View to display one of the fields for my content but that view is going to be dependent on which node I’m looking at. So again we’ll talk about the URL of the page that I’m looking at. It’s evolvingweb.ca/content/blogposttitle but that’s an alias, right. So the actual Drupal path is node/1 and I can use that URL, the node/1, to get the node ID, in this case it’s 1, and I can show the tags just for node 1. So I can still filter the content in my View so I’m only showing the content associated with the node that I’m looking at. So in the configuration, again, you’re adding the contextual filter and I’m adding the node ideas to contextual filters because that’s how I’m going to tell which node that I’m going to look at. Then in the configuration, you can choose to take the node ID from the URL. There’s a setting ‘provide default value for my contextual filter’ and one of the options is ‘content ID from a URL.’

So that’s just a quick overview of contextual filters and I’ll be talking about some of the use cases for that. So the user interface can sometimes be a little bit confusing at first to wrap your head around but I just want to give you an overview of some of the places where you can use this functionality on your site.

So one really useful thing you can do with contextual filters is to show related content or break up your content and show it in different places. Often in Drupal we kind of think of being confined to the node content area when we’re creating sites and so contextual filters lets you kind of break out of that and add Views in your sidebars or in other regions on your site relating that back to the actual content of the page that you’re looking at.

For example, if I want to show a field in a separate block, I can do that by adding a view to show that field and then using a contextual filter to relate the view to the node that I’m looking at.

Another example would be if you had a field that showed related content and then using a contextual filter to only show the field for the current node.

Another thing you can do with contextual filters is use it to exclude results. So the example, we just looked at was for only showing results for the current content but you can kind of do the opposite. You can say, “Okay, show me a list of the contents except for the piece of content that I’m looking at.”

The use case for case for this would be something like you’re looking at a piece of news or an article on your site and then in the sidebar you have a list of other news items or other articles, but you want to exclude the article that the user is currently looking at because of course they don’t need a link to that in the sidebar, they’re already there. So if you want to create this “More News” block or “Other News” you can actually exclude that current node from the results using contextual filters.

So how you do this, you set up the contextual filters like what we saw before. You add the contextual filter for the node ID and then you set that up to use the node ID from the URL. Then the settings for the contextual filter at the bottom, there’s this ‘More’ section which is extremely useful and it has a check box for ‘exclude’, which just lets you exclude the current item.

So the next thing I’m going to talk about is how to extend Views. So pretty much everything we’ve talked about up and until now has been part of the Views module, but there’s a lot of modules you can add to extend Views functionality so to add extra functionality for your Views.

One thing that’s incredibly useful in our Drupal site is to set up some Views for your administrators because often Drupal sites have a lot of content and it can be really useful for administrators to have Views just for browsing through that content and you can edit and manage the content of site.

The administrative Views module replaces the default content administration pages. So the default content administration in Drupal is a little bit clunky, it’s kind of hard to add filters and you can’t customize it. So administrative views add a View just to replace that page and it sets it all up for you so you don’t have to do any configuration if you don’t have time at the end of the project but you can go in and configure that and add more settings.

Another module you can use for your administrators is draggable Views and it’s a module that adds a field to your Views or allows you to add a field of Views, but associates an order with the Views results. So this is really useful if you have content that needs to be displayed in a very particular order, but the order is arbitrary so it’s not based on a certain criteria that already exist but you want your administrators to be able to display the results in whatever order they want. So for example, on a slide show on your site, you might want to let the administrator choose exactly which order the slides appear.

So draggable views allows you set up a display which an administrator can use to reorder the Views. So it gets you a drag and drop UI for changing the order of the results and then that ordering is going to impact the actual display that the users are going to see on the site. So it’s an extra display that you’re adding to your Views and then you’re given that UI to administrators to change the ordering of the results.

Another really important module for administrative views is view bulk operations and that sets up a UI where administrators can select multiple pieces of content and then do operations on them. So delete a whole bunch of content or publish it or change the status somehow and so if you set up a table view for your administrators and you have ‘views bulk operations’ enabled on your sites then you can add ‘use View bulk operation’ field which gives you a check box for each of the items in the View’s results. Then at the top there’ll be a form where you can actually do the operation on your content.

Another really powerful thing that you can do with the View is you can combine it with the Apache Solr module, which gives you search results which you can configure using the Views UI.

So basically, your search page will be powered by Apache Solr but you can change the configuration of the results and everything using the Views user interface that you’re used to. So adding fields, changing the formatting, all of the functionality that I’ve been talking about, you can do that for all your search results. So it’s a really powerful combination.

You can use Views to display at lot more types of data. Pretty much today, I’ve been using nodes as an example but of course you can use Views to display things like users and taxonomy terms. If you’re adding other modules to your site that provide other entities or other types of content then you can use Views to organize that too.

Most modules come with Views integration so you’ll be able to control the organization of that content view as well. So things like if you are adding products or media to your site using the commerce module or the media, then you can use Views to control how that content is displayed.

If you have custom data that you’re adding using a custom module, you can add Views integration yourself and there’s a post up on our blog about how to integrate Views with your custom data.

I’ll just run through really quickly a couple of modules you can add to add extra formats to your Views. So if you don’t want to display your contents in a table or a list but you want to add something that’s a bit more dynamic, you can use Views Slideshow for example, to show a rotator on the homepage of your site so each item in the slideshow is a Views results.

Views Slideshow gives you configuration for the transitions in the slideshow and how the controls work for it to change to the next slide. So all of that is added to the Views Configuration when you add a Views Slideshow.

The Calendar Module is another example of using an extra module to format your Views in different ways.

The calendar module gives you templates that you can use to add - so you are adding a new View but you’re using a template. So rather than adding it from scratch it’s going to give you some of the configurations for displaying your content in a calendar right out of the box. The user interface for that looks something like this.

So you get a single calendar view and you’ll have a display for how you want that calendar to show up. So it could be a month’s display that would be the most common type of display but you could also show a week’s display or a day display or a year display, and then you can go in and customize that.

You can also use Views to display maps. So if you have location data in your content and you’re using something like the open layers module just to show maps on your site then you can use Open Layers Views to display a list of content with the list formatted as a map.

So obviously, there’s a lot of functionality that you can build that with Views and you’ll probably be spending a lot of time if you’re a site builder just working with this Views UI.

So just a couple of things, a couple of tips when you’re working with Views. First of all, when you are editing your View, there’s a preview at the bottom of the Views Configuration UI that you can use to see what your View’s going to look like before you publish it. So if you’re doing a lot of work, it can save you time.

You don’t have to save the Views every single time you want to see the changes. You can also export your Views after you spend several hours working on your View.

You probably want to make sure that your changes don’t get lost or blown away. So you can export Views just in the built-in Views user interface. If you’re using the features module, which I highly recommend then you can add your Views to feature which effectively exports your Views into code and that way you can add them to version control and not worry about losing all of your changes.

If you’re a themer, and you’re not satisfied with all the markup that you can change through the configuration, there is a way to easily theme your Views results and the Views module comes with a theme information page or a link in the interface for your Views display. That’s going to show you exactly which templates you are using and help you overwrite those using your own custom templates and themes.

So lots of ways to plug into to Views and do custom theming with Views content.

I know I covered a lot of different topics today and hopefully I gave you a sense of what you can do with Views and a bit of an idea of how to do some of that configuration. If you want more information, I’m doing some upcoming Views trainings, one in Ottawa on May 13th and then also at DrupalCon Portland on May 20th. I think there’s one spot left in that class at Portland. So if you really want to learn more about Views then you can sign up today and get the last ticket. So I guess we might have a little bit of time for questions? Hannah, if you…

Female: Yes, thank you, Suzanne. We had a couple come in so we can answer those and then I think we can wrap up. So the first question that came in is there a way to convert a Views page to a Views block and vice-versa through the UI?

Suzanne Kennedy: No, there isn’t. You can clone - You can clone a display in Views. So if you have an existing block display or page display then you can clone that but it will still be a page display or block display and that’s because there’s certain settings associated with the fact that it’s a page or a block like the path for pages and then for blocks whether it’s link to a page.

Female: Great. We had one more question come in, if you have visual data and we choose the grid display, table format, how can that be responsive?

Suzanne Kennedy: That’s a really good question. So usually it’s pretty hard to make tables responsive. So I’ve seen people do different thing with grid displays basically changing it so that when you reduced it in size, it collapses down into single column displaying all the results just in one column rather than having multiple columns like you’d normally have a for a table. So for example if you go to the DrupalCon Portland website, on the attendees page there is a grid display and you can collapse that down and see how that behaves but that’s what that View does.

Female: Okay. We have one last question. How do you display data in charts and graphs?

Suzanne Kennedy: Okay. Another good question. So charts and graphs similar to things like maps and slideshows, it’s kind of different way of formatting the data. So you’d want to look into some of the modules out there for Drupal that give you charts and graphs functionality. I can’t think of the names off the top of my head but basically you’re looking for modules with Views Integration that let you add charts and graphs. Then that would be another formatting option. So if you click on format then you’d be selecting the option to use that module’s formatting through interface that way.

Female: Great. Thank you so much, Suzanne. Thank you everyone for attending. Again, the slides and recording of this webinar will be posted to the Acquia.com website and we’ll also email you out a copy. Thank you, Suzanne, so much for your great presentation and answering those questions. Do you want to end with anything?

Suzanne Kennedy: No, I guess just thanks everyone for coming. I know it was a lot of information but I’m sure if you look over the slides, you’ll get a better idea of where to look in the UI and best of luck with Views configuration.

Female: Thanks so much.

Suzanne Kennedy: Thanks.

Bâtir votre Réseau Social d'Entreprise avec Drupal Commons 3 [April 25, 2013]

Controlling Your Site Layout Using The Mobile-First Omega Theme [April 24, 2013]

Introduction to Marketing Through Communities and Enterprise Social Networks [April 17, 2013]

Harnessing the Power of Open Source and Drupal to Drive Patient Outcomes in Healthcare [April 16, 2013]

How to Create a Personalized Experience, Drive Sales with the Evergage Drupal Module [April 11, 2013]