After the initial official release of Views 2 nearly two weeks ago, we felt the need to give an official rundown of how we have incorporated some of its features into our production sites. There really are too many new features to discuss in one blog post, but I will try to cover a few new features for site administrators, developers, and themers.
What is Views?
If you're not familiar with Views already, it can be a bit challenging to explain. Views is the most actively used contributed module in the Drupal repository. On the most basic level, it is used to create lists of data. The majority of a website is built upon two concepts: the first being data, the second being presentation of this data. It is for this reason that views is a vital element of many sites.
Views gives you the option to filter the data outputted by a variety of options -- including but not limited to: node type, author, taxonomy term. It also allows you to sort by a variety of different options, including: post date, updated date, number of page views, etc. The list of data can be unformatted or outputted via a table, grid, list, river-of-news, etc.
Using Views, one can create countless lists of data such as:
- River of news
- Image gallery
- User lists
- Highest-rated content
And all this can be done without touching a bit of code.
A Greatly Improved User Interface
The most obvious change with the Views 2.0 is the user interface itself. What used to be thousands of pixels in height now fits before the first page fold in a completely revamped interface.

For example, if you had a page and a block display both showing the most recent 5 blog entries posted to your site, you could simply change the ‘Default’ display to show the most recent 10 entries, and that setting would trickle down to all other displays. This functionality alone decreases the amount of time needed to create and update views drastically. (Of course, one can set a display to override the default display on a per-configuration setting basis.)
Not only has the interface for creating and editing views improved, but you can now create views which are more complex. To begin, no longer is Views node-centric - meaning that one can create lists of almost any data stored in the database, from users, to comments, files, revisions, and taxonomy terms. This opens up a whole new use for views, which, before, was reserved for custom queries.
Views as Attachments
Another new feature of Views is the ability to attach view display to another. By creating a display type of ‘Attachment,’ one has the option to amend or prepend one list of data with another.
For example, creating a gallery-type view which displays the most recent image enlarged with the description to the right, and the next six most recent images’ thumbnails below is entirely too easy with Views 2 and imagecache. Simply create a display which outputs two fields: the first being the image using a large imagecache preset, the second being the node body (or other description field). Then, create an attachment display, which displays a total of 6 nodes offset by 1 (to account for the first large image), and set the imagecache preset to be a smaller thumbnail. Then, simply select your attachment display to propend to your first display, add a bit of CSS to float the large image to the left and bingo, you have a single view that looks like this:

Sample images' source: commons.wikimedia.org
Relationships in Views, and Advanced Help
Another fantastic feature is the ability to define relationships in a view. A relationship allows you to expand the original query to include additional objects.
For example, if you are using a nodequeue to order your nodes, you might want to create a view which is sorted by order within the nodequeue. Simply add a relationship to the nodequeue within the views interface, and you will see a new sort option appear: 
You will notice notice in the above screenshot that there are question-mark icons next to Relationships and Sort criteria. These were added via the Advanced Help module, which makes accessing help much easier. For a feature rich module such as views, this functionality is extremely helpful.
Easy Views Theming
Theming a 1.0 View used to be a daunting task. Figuring out which theme functions to override was often difficult and, simply put, was too complicated for beginning themers. Now, Views 2.0 uses a template-based theming system. All of the information as to which tpl files to create is accessible through the user interface under Base Settings > Theme > Information. Moving to a template-based system makes the life of a themer much brighter.
Although all of the discussed features are quite wonderful, the most useful addition to Views 2 is, undoubtedly Live Preview. No longer do you have to save your view, which tabs, and refresh. Instead, everything is handled on one screen, allowing you to work more efficiently.
Views + [other Drupal modules]
There are many contributed Drupal modules that integrate well with Views, making Views all the more powerful and useful.
For example, we are using Views to handle some complex workflows. With the combination of Workflow, Actions, Triggers, NodeQueue, and Views, one can create a feature-rich site that handles complex content creation workflows demanding moderation, approval, and promotion stages. Workflow integrates seamlessly with Views, allowing you to create lists of all nodes in a certain state. Integration of Workflow with Views also adds many other useful filters, sorts, and fields.
We have also used Views to create a custom search page with customizable sort options. It seems that almost every week we find a new use for Views that shortens our time spent on these types of tasks, allowing us to spend more time making sites even more functional than before.
A Valuable Drupal Toolset Created by a Most-Valuable Drupal Player
A special shout out from all of us at pingVision to Earl Miles (merlinofchaos) who was recently voted Drupal's MVP by Packt Publishing mainly for creating such a wonderful contribution to the Drupal community.









Comments
Anonymous writes:
This is very helpful. Thank you!
Kristen writes:
Wow. This is awesome. I didn't know about the attachment stuff and I am *definitely* going to use that to do some complicated pages particularly since panels is still beta for drupal 6. Thanks for taking the time to write this detailed tutorial
Anonymous writes:
When you said (regarding attachment):
"...Then, create an attachment display, which displays a total of 6 nodes off set by 1 (to account for the first large image)..."
I am not entirely sure how to do that... where is the "off set" command you are referring to?
Thank you.
Matt Tucker writes:
Thanks for the comment. Very sorry for the typo there. That should read "offset". This setting is accessible through the Basic Settings panel under Items per page. Here you can not only set the number of items to display, but also from which item in the list to begin counting. Hopefully this clears things up a bit.
Sott writes:
This is pretty neat, but can you use more complex logic than a simple offset? For example, using the image series example above, could you modify it to present all the images in the series but excluding the main featured image?
Matt Tucker writes:
This type of logic is really not needed, because somehow you must decide which image is 'featured'. Whether the full list is sorted by post date, or nodequeue position, or otherwise, using the offset will always work.
If you want a bit more control, you could configure an argument on the 'featured' view which displays the node id given through the URL. Then, configure the attachment to use the same argument, but, configure this to "Exclude the argument". This would allow you to pass any node id to the view. This would 'feature' that node id, while displaying all other nodes fulfilling the same criteria given in the filters in the attachment.
With views, there are many possibilities, and the example provided above is merely to introduce attachments and the power that they provide.
Lopsta Ecommerce writes:
i have never tried views 2, but i love views in general. the admin interface of views 2 looks awesome, you can smell the power behind it. need to try it soon.
markosef writes:
Hi, nice text. Have one q. tough.
" Then, simply select your attachment display to propend to your first display"
you say this, i am doing just the same right now and it works nicely, but problem is when u click on other images (if nodes) you then lose the view and get to node view. So seems stuff is missing to make them perfect as seems to me that i need to hack theme than to add links to other images/nodes or am i missing something?
Matt Tucker writes:
If I understand your 'problem', you are not missing anything. The outcome that you are seeing is exactly what was originally intended for this example. There are many possibilities to achieve what I believe you are wanting. Our personal favorite is to use Nodecarousel, a module coded by our own John Fiala.
The above example was set up merely to show the power of attachments and hopefully give readers ideas of how to incorporate them into their everyday work. But, as with everything with drupal, there are many ways to accomplish one task, and it is important to use the right tool for the right job.