Add a contextual filter to a view

Last updated on
13 August 2024

This documentation needs work. See "Help improve this page" in the sidebar.

[INCOMPLETE]

You can configure a view so that it is filtered dynamically, depending on the context. For example, you could use a contextual filter to add a block that contains related content or that presents a list of articles by the same author.

Prerequisite: To create a contextual filter that is based on a context other than the information in the URL, you may need to create a relationship. For more information, see Add a Relationship to a View.

  1. Navigate to the edit screen of a view (for example, admin/structure/views/MY_VIEW_NAME/edit).
  2. Click Advanced.
  3. In the Contextual Filters area, click Add.
  4. From the Add Contextual Filters list, select one or more filters and click Apply and Configure Contextual Filters. The Configure Contextual Filter dialog box displays.
  5. In section When the filter value is NOT available, specify one of the following options:
    • Display all results for the specified field
    • Provide default value
    • Hide view
    • Display a summary
    • Display contents of "No Results Found"
    • Display "Access Denied"
  6. Choosing Provide default value offers the following options:
    • Content ID from URL
    • Fixed (you enter the value)
    • Query parameter
    • Raw value from URL
    • Taxonomy term ID from URL
    • User ID from logged in user
    • User ID from route context (typically this means from the URL)
  7. If you want to specify different behavior for certain situations, in the Exceptions section, specify a value for exceptions.
  8. In section When the filter value IS available or a default is provided, specify one of the following options:
    • Override title
    • Specify validation criteria
  9. Click Apply and Continue. Repeat steps for each selected filter. Note that steps 5-8 are optional; you might use one or all of them depending on your use case.

Help improve this page

Page status: Needs work

You can: