Views UI: Query, List, and Display Content

Learn about the advanced filtering features of Views, customizing the output, and giving users control over filter criteria.

This course assumes you’re already familiar with the basics of what Views are and how they work. The tutorials in this course cover advanced features of the Views module, including adding and configuring filter and sort criteria, exposing these criteria to users, and using relationships and contextual filters to refine the data displayed. Additionally, you will learn how to theme Views using template files.

Key topics

  • Adding and configuring filter criteria to refine view results
  • Adding and configuring sort criteria to order view results
  • Exposing filter and sort criteria to users for interactive filtering and sorting
  • Using relationships to connect related data in views
  • Implementing contextual filters for dynamic content filtering
  • Theming views and overriding view templates

Author, Jonathan Daggerhart

Jonathan Daggerhart (daggerhart on Drupal.org) is a Drupal and WordPress developer who has worked with and contributed to both systems for over a decade. He has presented at multiple Drupal and WordPress camps on topics for both beginner and expert developers. Jonathan is also an organizer of Drupal Camp Asheville.

Tutorials in this course
More information

To follow along with our Drupal Views tutorials, set up a Drupal site loaded with our 4 custom views and baseball stats content that will make querying in Views a bit more interesting and meaningful.

By the end of this tutorial, you should choose a solution and follow the instructions for creating a Drupal site loaded with our starting point content and views.

Categories
Drupal 8, 9, 10, and 11
More information

One of the ways you can create a REST endpoint in Drupal is by using Views. In this tutorial, we'll add a REST endpoint display to a view of baseball players. We'll examine and configure settings that are unique to the REST endpoint display.

By the end of this tutorial you should be able to:

  • Add a REST endpoint display to a view
  • Understand how to configure settings for an endpoint
Categories
Drupal 8, 9, 10, and 11
More information

With filters, we can define query conditions and refine the results of a view. But what is a filter and how do filters work in Views? In this tutorial, you'll learn:

  • How to add and configure filter criteria to a view to refine results
  • What configuration options are available for filter criteria operators
  • How filter groups allow you to group and order filter criteria to achieve desired results

By the end of this lesson, you should understand how to use and configure filter criteria in Views to refine the results of your view. (Note: We'll cover exposed filters in Overview: Exposed Filter Criteria in Views)

Categories
Drupal 8, 9, 10, and 11
More information

In this tutorial, we'll walk through the process of adding and configuring filters and adding a filter group.

More information

Exposing filter criteria allows the users of your site to choose how to filter a content list created in Views. When rendered on the page, the exposed filters will be displayed to the user as interactive form components.

By the end of this tutorial you will:

  • Understand what it means to expose filter criteria and when it might be useful.
  • Be able to identify when a view has exposed filters and which filters are exposed.
Categories
Drupal 8, 9, 10, and 11
More information

Instead of providing multiple views with different filter criteria, consider empowering your users by exposing filter criteria as an interactive form. You can even configure the forms to use AJAX to refresh results. In this tutorial, we'll walk through the process of adding and configuring exposed filter or sort criteria in a view.

Categories
Drupal 8, 9, 10, and 11
More information

With sort criteria, we can specify how to order our list. We can specify sort criteria using any field on or related to our view's base entity, and then specify in which order to sort, e.g. ascending or descending. If you are familiar with MySQL, it may be helpful to know that sort criteria are the ORDER BY clause of the query that Views builds. In this tutorial, you'll learn:

  • How to add and configure sort criteria to a view to sort the list in various ways
  • What configuration options are available

By the end of this lesson, you should understand how to use and configure sort criteria in Views. (Note: We'll cover exposed sort criteria in Overview: Exposed Sort Criteria in Views)

Categories
Drupal 8, 9, 10, and 11
More information

In this tutorial, we'll walk through the process of adding and configuring sort criteria to a view.

Categories
Drupal 8, 9, 10, and 11
More information

Exposing sort criteria allows the users of your site to sort a view using an interactive form.

By the end of this tutorial you will:

  • Understand what it means to expose sort criteria and when it might be useful.
  • Be able to identify a view's exposed sort criteria.
Categories
Drupal 8, 9, 10, and 11
More information

Like exposed filters, we can expose sort criteria to the site visitor. Exposing sort criteria gives the visitor more control over the list of content they are viewing. In this tutorial, we'll configure our view of baseball players to allow visitors to sort the list in different ways by adding several exposed sort criteria.

Categories
Drupal 8, 9, 10, and 11
More information

In order to display values for referenced entities in views, you need to add a relationship. What is a relationship, how do they work, and what does it mean to require this relationship? What are some common use cases for adding a relationship to a view? By the end of this tutorial you should be able to:

  • Explain some common use cases for adding a relationship to a view.
  • Understand the concept of entity references and how those field values can be displayed in a view.
Categories
Drupal 8, 9, 10, and 11
More information

Now that you understand the purpose of relationships in Views, let's add a relationship to a view so that we can access and display a field value from a related entity.

In this tutorial, we'll modify the Player Awards view to add a relationship to the player that received the award. Then we will add a field that belongs to the player content that would normally not be available to the view without our new relationship.

Categories
Drupal 8, 9, 10, and 11
More information

Contextual filters are a Views mechanism for dynamically refining the contents of a view. It might be helpful to think of them as "dynamic filters". In this tutorial, we'll discuss the concept of context, look at how to add contextual filters in the Views UI, and review the Taxonomy term view that comes with Drupal and how it uses a contextual filter.

Categories
Drupal 8, 9, 10, and 11
More information

In this tutorial, we'll add and configure a contextual filter for a view. Our Baseball Awards content type has a field Year. We'll make it possible for a page to be dynamically created on our site that contains the year and lists the awards for that specific year. To do this, we'll add a contextual filter to the Baseball Awards view that will allow visitors to filter the list of awards by the award year. We'll also add a block using the summary view contextual filter configuration, which visitors can use to view results for specific years.

Categories
Drupal 8, 9, 10, and 11
More information

Like most output in Drupal, Views relies on Twig templates for a significant amount of its rendering. In this tutorial we'll identify where you can find the default Views templates within your file system, what the common templates are for, and how to name your templates so that they are applied to specific views.

By the end of this tutorial, you should be able to:

  • Identify where to find default views templates
  • Understand which templates apply to what part of a view
  • Get a sense of the template suggestions and how to use them to limit where your custom templates are applied
  • Identify a view's machine name
  • Identify a display's machine name
  • Identify a field's machine name
Categories
Drupal 8, 9, 10, and 11
More information

Now that we understand what templates are and how we can use them, let's override some templates! In this tutorial we'll copy the views wrapper template to our theme and override it so that we can customize the markup for the Baseball Players view. Then we'll modify the template so that our view's pager appears both above and below our table of players.

This course appears in the following guides:
Site Building
Learn how to query, list, and display your content using Views UI and Views API.

Views in Drupal