Introduction to the Drupal Views Module

The Drupal Views module is an important component that controls the way content is retrieved and displayed. It provides very fine control over the sorting of information, the display of certain types of content, and the layouts that you can use, without the hassle of custom coding.

Views also happens to be the most downloaded module in the history of Drupal. In 2012, analysts believed that the Views module was used on more than 70% of Drupal websites. Up until version 7, Views had to be downloaded and installed manually. From version 8 onwards, Views has been bundled with the Drupal core code.

If you're working with a version that doesn't include views by default, head to Admin, then Structure, and look under Content Types to see if it's already installed in your version.

How the Views Module Works

The Drupal Views module provides two different functions:

  • The query builder component is the part that actually pulls your data from the database.
  • The display component determines the way that the content will be output on your website.

Together, these two functions make it relatively easy to display dynamic content in Drupal, without the need to write raw code. You don't need to know anything about SQL to build the kind of pages your website requires, and you can create everything from simple lists to complex data visualizations. The Views module is instrumental in building relatively simple layouts, such as a blog archive, but can potentially scale up for more complex purposes.

Using Views

The Views module includes a submodule called Views UI, which provides the wizard-style interface that you use to build queries and displays. Views UI isn't the most intuitive tool at first glance, but this is partly because the wizard lets you do a lot in a relatively compact interface. You don't need to use every part of it until you become more confident.

At a high level, there are three steps to building a dynamic view of your content.

Initially, you select the base table that contains the data you want to retrieve. This might be a node or a comment table. You can then select the way you want to sort the information.

The Views UI also offers various ways to display that information: as a page or a sidebar block, for example. You can choose which fields you want to use in your display, and specify how the data will be filtered and sorted. Optionally, you can also include an RSS feed, add a menu link, and include pagination if your selection supports it.

Finally, you will specify an HTML output style, which is also known as a display. This means specifying the title for the page, the filtering criteria, and any header or footer that you want to include. Views allows you to create a default placeholder that's displayed if the query returns no results. You can customize the size of the output, or let the user control the way the information is sorted. Views lets you specify multiple displays, so you can clone the same Display settings to all of them, or override the default behavior.

Advanced Usage of Views

Views isn't just a way to display static content. You can build displays that incorporate interconnected content using Relationships. This is essentially a join operation, where you use information from one table to locate corresponding information in another. For example, using a Relationship, you could look for all of the content written by a particular author.

Drupal 8 also provides updated contextual filters, which you can used to dynamically drill down into the data further. You can pass information using URL arguments or controls on your page, and then tell Drupal what to display when those arguments are specified.

Resources For Drupal Views, Pre-Version 8

Resources For Drupal Version 8 and Beyond

Summary

The Views Module is a powerful addition to Drupal and well worth the time to learn. Check out some of the references above to get on your way.


Further Reading and Resources

We have more guides, tutorials, and infographics related to website development and management — especially related to Drupal:

Ultimate Guide to Web Hosting

Check out our Ultimate Guide to Web Hosting. It will explain everything you need to know in order to make the best choice for your Drupal instal.