What Are Drupal "Views"?

Definition:

The Drupal Views module allows you to organize and show your content to the world in almost any way you can think of. Over half a million Drupal sites report that they use the Views module. It's that good.

For instance, let's say you have a custom content type for book reviews. Each book review includes the following fields:

  • cover image
  • title
  • author
  • publisher
  • publication year

By default, Drupal will let you make a basic listing of these reviews.

You can hide or show each field in the listing, and set the size of the cover image. And not a whole lot else.

Mix and Match Your Content

With Views, on the other hand, you can mix and match this data into all kinds of custom listings. For instance, you could:

  • Have a page that lists all books by only their title. Each title links to the full review.

  • Have another page that lists all the authors you've reviewed. Each author links to a short listing of titles by that author.

  • Have a third page that is only cover images, in a grid. Each image links to the full review.

  • Have a sidebar that shows only the thumbnail cover image and teaser for your six most recent reviews. Further, you only show those books which are tagged with the terms "western", "mystery", or "readable Star Trek fan fiction".

And those examples are just off the top of my head. If you can think it, it's very likely you can build it in Views.

Look, Ma! No Code!

And you can build all these views without a single line of code.

If you had to do a view in code, it would look something like this:

SELECT node.nid AS nid,
node.created AS node_created
FROM node node 
LEFT JOIN term_node term_node ON node.vid = term_node.vid
LEFT JOIN term_data term_data ON term_node.tid = term_data.tid
WHERE (node.status = 1 OR (node.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0) OR ***ADMINISTER_NODES*** = 1) AND (node.promote <> 0) AND (UPPER(term_data.name) = UPPER('blog'))
ORDER BY node_created DESC

And that's just the MySQL query.

You'd also need code to format and output the results. If you ever wanted to add a field or a condition, you'd have to dive in and tweak the code without breaking anything.

Views? Point and click.

Thinking in Content Types and Views

As you learn to work with custom content types and views, you'll discover that they can solve a huge percentage of hitherto intractable CMS problems.

So often, you or your client will want "special" pages that, on other CMS software, would require complex coding, or a desperate hunt for a plugin. But with a little thought, you can reduce them to one or more custom content types, and a well-built view.

Extend Views With Custom Modules

True, views can't do everything. But if you ever find yourself up against the limits of Views, check drupal.org. There are thousands of modules that extend Views. As always, you should choose modules wisely, but it's quite possible that someone's already solved your problem.

But Learn Views First

But before you go looking for a custom module, make sure you've really learned what "basic" Views can do. There are plenty of tutorials out there, but the best way to learn is to enable one of the included views.

Right away, you'll see the basic elements you need to make a view. Then you can start tweaking -- and that's the best way to learn.