fromMarch 2011
Article:

What Is This Views Thing, And Why Do I Need It?

0

If you ask Druplicon, the friendly IRC bot in the various Drupal channels on freenode, it’ll tell you this: Views will help you create lists and tables. Its primary purpose is to build queries to retrieve data from your datastore, be it a database or something like the Amazon.com API. It can help you create blogs, lists of news items or album tracks, photo galleries, and many other things.

Knowing something about how SQL queries are structured goes a long way toward making Views usable quickly. But even if you’re not familiar with writing your own queries, learning a few things about Views can make sure you never want to try. Each configuration box contains a group of settings that deals with a particular function or task.

Views’ user interface is loaded with configuration options, and can be intimidating to a new user. The first thing to understand is the type of data you’re looking for. Do you want content like blogs or news articles? Do you want a different way to list your users? Do you want items by taxonomy? Once you know this, it’s easy to pick the right kind of View to create.

The second thing to know, which seems to trip people up regularly, is the filter “Node: Published = Yes”. Views keeps on the side of caution by not showing everything; you need to tell Views to show content. Beyond that, there are nearly uncountable things you can do with Views!

The main Views UI is essentially split into two sets of functions: settings, and field configuration. The settings describe how the view should look, whether it should have a pager, use AJAX, and many other things. The field configuration boxes are entirely about the content, describing what data will be shown, and what order it will be shown in.

The settings have little or nothing to do with the actual content of the view itself. These are broken down into further groups. Use these to give your view a tag, turn on a more link, create a pager, turn on grouping, set up caching, and other things. In general, it describes what your View can be described as, and where it can be seen.

Basic settings give you a name and a title, which help you make your view easier to identify. Here also are the pager settings, if wanted, enabling the use of a full or a mini page, how many items and so on. A more link can be configured here if the view has a limited number of items to show in a given display, as well as the setup to control access to the view. Advanced settings bring in features that new users to Views may find useful but require more experience in order to utilize correctly and fully. AJAX for automatic refreshes, grouping for changing your filters between AND and OR SQL statements, caching to improve performance, and query settings to disable SQL rewriting and forcing DISTINCT values in the view when possible. These advanced settings all require some understanding of performance impacts and SQL to evaluate when it’s the right time to use these.

The field configuration is where the real magic of using Views starts to happen. These boxes are all about what your view will show people. By using a combination of arguments, filters, sorting, and fields, a view comes to life. Fields are the easiest to grasp – they come directly from whatever content is chosen at the creation of the view (node, user, etc.) Everything else modifies these fields and which fields to show the user. Filters can modify results to a particular type of item; while sorts determine the order those items are in (and more, depending on your version of Views). Arguments operate somewhat like filters, but where filters are explicitly defined, arguments often are fed from elsewhere, like the URL of the page being visited.

The last thing that Views brings to the table are relationships. They’re possibly the most complex area in the core of Views. Not all data is available to a particular view at creation, but a relationship can bring data from other tables into play for display. For example: voting data can be added to nodes, but is not part of the back end node table in the database; a relationship can determine how the votes are related to a node, and make that data available for display in the view.

Using all of these tools, you can create myriad lists of just about anything in Drupal. Things like top news stories, album tracks, blog posts related to an image, and schedules of classes are just the tip of what Views can do. These are just the barest basics of Views’ features; the Advanced Help module brings out Views’ documentation, and there are many handbook pages on Drupal.org, as well as published books on Views to help you really delve into using this powerful module.