Building Dynamic Content Lists in Drupal Using the Views Module
Learn how to use the Drupal Views module to create dynamic, filterable content lists with pagination and contextual filters to improve site navigation and performance.
01 Sept 2025, 01:39 UTC

The Challenge: Displaying Filterable Content Without Custom SQL
Manually writing queries to pull specific content types, filter them by category, and implement pagination is time-consuming and difficult to maintain in Drupal. The Views module solves this by providing a UI-driven query builder that translates configuration into optimized SQL, allowing you to create dynamic lists—such as "Latest News" or "Product Directories"—that update automatically as content changes.
Prerequisites
- Drupal installation (version 9 or 10) with the core Views module enabled.
- At least one Content Type (e.g., "Article") with several published nodes to verify pagination and filtering.
- Administrative permissions to access
Structure > Views.
Step 1: Initialize the View
Navigate to Structure > Views and click Add view. To ensure the list is dynamic, configure the following:
- View name: Give it a descriptive name (e.g., "Staff Directory").
- View settings: Select "Show: Content" of type "Article".
- Page settings: Check "Create a page". Set the path (e.g.,
/news-archive) and choose the display format (e.g., "Unformatted list" or "Table").
Step 2: Configure Pagination (The Pager)
Displaying hundreds of items on one page degrades performance and user experience. To implement pagination:
- In the Pager section of the View configuration, select Use a pager.
- Choose Full pager for numbered page links or Mini pager for "Next/Previous" navigation.
- Set the Items per page to a manageable number (e.g., 10).
Step 3: Implementing Fixed and Exposed Filters
Filters restrict which content appears in the list. You can use Fixed filters (hidden from users) or Exposed filters (user-facing search inputs).
To add a category filter:
- Under Filter Criteria, click Add.
- Search for the field you wish to filter by (e.g., "Content: Category").
- Select the operator (e.g., "Is one of") and choose the desired values.
- To let users choose the category, check the Expose this filter to visitors box.
Step 4: Adding Contextual Filters for Dynamic Routing
Contextual filters allow a View to change its output based on the URL. For example, if you want a page that automatically shows all articles written by the author identified in the URL path /author/[user-id]:
- Under Advanced, locate Contextual Filters and click Add.
- Select "Content: UID" (User ID).
- Under "When the filter value is NOT available", select Provide default value and choose "User ID from URL".
Configuration Comparison: Pager Types
| Pager Type | User Experience | Performance Impact | Best Use Case |
|---|---|---|---|
| Display all | Single long scroll | High (Memory intensive) | Small sets (< 50 items) |
| Mini Pager | Next/Prev links | Low | Simple chronological feeds |
| Full Pager | Numbered page list | Moderate (Requires count query) | Large archives/directories |
Verification and Testing
To verify the implementation, perform the following checks:
- Pagination Check: Navigate to the View path. Ensure that if you have 15 nodes and a limit of 10, a second page exists and is accessible via the pager.
- Filter Check: Use the exposed filter form. Submit a value and verify that the result set updates to match only that criteria.
- URL Check: For contextual filters, manually enter a known User ID in the URL (e.g.,
/author/1) to ensure only that user's content appears.
Performance Limitations and Risks
While Views is powerful, it can introduce database bottlenecks:
- Join Bloat: Adding too many relationships (joins) to other entities can slow down query execution. If a View becomes sluggish, check the database indexes on the filtered fields.
- Caching: If content updates are not appearing, check the Caching settings under the Advanced tab. Ensure the cache is set to "Tag based" to allow Drupal to invalidate the cache when a node is edited.
Rollback Procedure
Because Views are stored as configuration objects, you can revert changes by:
- Navigating back to Structure > Views.
- Clicking Edit on the View and manually reverting the filter or pager settings.
- If the View was deployed via Configuration Management (CMI), use
drush config-importto restore the previous known-good state from your version control system.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.