Drupal Views Module โ Building Dynamic Content Lists Without Code
In this tutorial, you'll learn Drupal's Views module including creating views with displays for pages, blocks, and REST exports, configuring filters, sorts, relationships, contextual filters, and exposed filters for dynamic content listings.
What You'll Learn
- What Views is and the types of lists it can create
- Creating a new view through the Views UI
- Configuring displays: Page, Block, RSS Feed, REST export
- Selecting fields, filters, and sort criteria
- Using contextual filters to dynamically filter content
- Setting up relationships to join related entity data
- Creating exposed filters for user-facing search
- Views Caching for performance optimization
Why It Matters
Views is the most powerful module in Drupal and the primary reason many developers choose the platform. It allows site builders to create complex database queries through an intuitive UI, generating everything from content listings to REST API endpoints without writing a single line of SQL or PHP. Mastering Views makes you capable of building any content listing requirement without custom code.
Real-World Use
An online magazine uses Views for their entire front-end: a front page showing the latest 10 promoted articles (with image, author, and comment count), a "Most Popular" sidebar block (sorted by view count), a category listing page (with contextual filter for taxonomy term), a search results page (with exposed filters for content type, date range, and category), and a REST export for their mobile app -- all built with Views.
Learning Path
flowchart LR A[Entity System] --> B[Views Module] B --> C[Media] C --> D[Revisions] D --> E[Blocks] E --> F[Menus]
What is Views
The Views module (in Drupal core since version 8) provides a graphical query Builder that creates lists, tables, grids, and other displays of content. It replaces the need for custom SQL queries in most cases.
Views can query:
- Content (nodes): Articles, pages, custom content types
- Files: Uploaded images, documents
- Users: User accounts
- Taxonomy: Terms and vocabulary data
- Custom entities: Any entity type including custom ones
Views UI
Navigate to Structure > Views > Add view (or /admin/structure/views/add).
View Basic Information
- View name: Human-readable name
- Machine name: Auto-generated from name
- Description: What this view does
- Show: Choose the base entity type (Content, Files, Users, Taxonomy)
- Tagged with: Optional categorization
Initial Settings
- Create a page: Check to create a page display with a path
- Create a menu link: Adds a menu link for the page
- Include an RSS feed: Adds RSS feed display
- Items to display: Number of items per page
View Displays
A single view can have multiple displays, each with its own configuration.
Page Display
The page display creates a visible page at a specific path.
# Page display settings
Display: Page
Name: Page
Title: Latest Articles
Path: /articles
Menu: Main navigation > Articles
Access: Permission > View published content
Block Display
The block display creates a reusable block that can be placed in theme regions.
# Block display settings
Display: Block
Name: Sidebar
Block name: Recent Articles
Admin label: Recent articles sidebar block
Allow settings: Tick checkboxes as needed
RSS Feed Display
Creates an RSS feed accessible at a specific path.
# RSS display settings
Display: Feed
Name: Feed
Path: /articles/feed
Title: Latest Articles RSS Feed
Settings: Number of items, description
REST Export Display
Exposes data as JSON or XML for headless/decoupled Drupal.
# REST export display settings
Display: REST export
Path: /api/articles
Authentication: cookie
Format: json
Serializer: json
Other Display Types
- Attachment: Appended to another display (e.g., a map attachment to a listing)
- Entity reference: Provides data for entity reference fields
- Data export: CSV, XLS, TSV export (requires Views Data Export module)
Fields Selection
Fields determine what data columns appear in the view output.
Common fields for a content view:
- Node: Title: Content title, linked to content
- Node: Type: Content type label
- Content: Published: Published status
- Content: Updated date: Last modification timestamp
- Content: Author: Author username, linked to profile
- Field: Image: Image with image style
- Taxonomy: Tags: Taxonomy term labels
# Field configuration example
Fields:
- title:
label: Title
type: entity_label
settings:
link: true
- field_image:
label: ''
type: image
settings:
image_style: thumbnail
- created:
label: Published
type: timestamp
settings:
date_format: 'medium'
- body:
label: ''
type: text_summary_or_trimmed
settings:
trim_length: 200
Filter Criteria
Filters narrow down which entities appear in the view.
# Common filter criteria
Filters:
- status:
id: status
table: node_field_data
field: status
operator: '='
value: '1'
expose:
operator: ''
group: 1
- type:
id: type
table: node_field_data
field: type
operator: 'in'
value:
- article
expose:
operator: ''
group: 1
Sort Criteria
Sort criteria determine the order of items in the view.
# Sort criteria configuration
Sorts:
- created:
id: created
table: node_field_data
field: created
order: DESC
expose:
label: ''
- title:
id: title
table: node_field_data
field: title
order: ASC
Contextual Filters
Contextual filters (formerly "arguments") pass dynamic values from the URL to filter the view.
# Contextual filter by taxonomy term ID
Contextual filters:
- tid:
id: tid
table: taxonomy_term_data
field: tid
title: 'Posts in %1'
default_argument_type: taxonomy_tid
specifier: tid
validate:
type: taxonomy_term
fail: 'Page not found'
Common use cases:
# Filter by year and month from URL
Contextual filters:
- created_year:
id: created_year
table: node_field_data
field: created_year
title: 'Posts from %1'
- created_month:
id: created_month
table: node_field_data
field: created_month
title: 'Posts from %1-%2'
URL: /articles/2026/06 returns articles from June 2026.
Relationships
Relationships join related entity data to the view.
# Relationship to author
Relationships:
- uid:
id: uid
table: node_field_data
field: uid
required: false
plugin_id: standard
After adding a relationship, you can add fields from the related entity:
# Author fields via relationship
Fields:
- user__uid:
id: user__uid
table: users_field_data
field: uid
relationship: uid
label: 'Author Email'
Exposed Filters
Exposed filters allow site visitors to filter the view themselves.
# Exposed filter configuration
Filters:
- field_tags_target_id:
id: field_tags_target_id
table: node__field_tags
field: field_tags_target_id
relationship: none
exposed: true
expose:
label: 'Filter by tag'
identifier: tag
remember: false
multiple: true
operator: 'or'
is_grouped: false
group_info:
label: 'Tag'
Exposed filter settings:
- Label: Visible label for the filter
- Identifier: URL query parameter name
- Remember: Keep filter selection across page loads
- Multiple: Allow selecting multiple values
- Operator: AND or OR logic for multiple values
Paging
Configure how many items appear on each page.
# Paging settings
Pager:
type: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
tags:
first: 'ยซ First'
previous: 'โน Previous'
next: 'Next โบ'
last: 'Last ยป'
Pager types:
- Full: Complete pager with first, previous, next, last
- Mini: Previous and next links only
- Some: No pager, specified item count
- None: Display all items
Views Caching
Views can cache query results and rendered output for performance.
# Caching settings
Caching:
type: time
options:
results_lifespan: 3600
output_lifespan: 3600
Caching options:
- None: No caching, fresh query on every page load
- Time-based: Cache for a specified duration
- Tag-based: Invalidate cache when related content changes (recommended)
Style Plugins
Views supports multiple output styles:
- Unformatted list: Sequential items
- HTML list: Items in
<ul>or<ol> - Table: Tabular layout with sortable columns
- Grid: Items in a grid layout
- RSS Feed: XML RSS output
- JSON: JSON output for REST export
- CSV/Data export: Tabular data export
Common Mistakes
- Overriding the base view instead of creating a new one: The "frontpage" and "taxonomy_term" default views are essential. Always duplicate or create new views rather than modifying the defaults.
- Not using relationships when you need data from related entities: If you need to display the author's email, add a relationship to user rather than expecting the field to appear without a relationship.
- Forgetting to configure access for REST displays: REST export displays need authentication configuration. Without it, anonymous users may not receive data even if permissions are set.
- Ignoring Views caching: Without caching, every page load runs a fresh database query. For moderate traffic, enable time-based or tag-based caching.
- Using too many fields in a single view: Each field adds database joins and processing overhead. Only include fields you actually display. For complex data needs, consider custom Views plugins.
Practice Questions
- What is the difference between a filter and a contextual filter in Views?
- How would you create a view showing the 5 most recent articles by a specific author, displayed as a block in the sidebar?
- If you need to display a table with article titles, author names, and the number of comments each article has, what relationships and fields would you configure?
- Challenge: Build a complete Views solution for an event listing site: create a page view at
/eventslisting upcoming events (filtered by date >= today), sorted by date ascending, with a grid display showing event image, title, date, and category. Add a sidebar block showing upcoming events grouped by month. Add a REST export at/api/events.jsonreturning event data as JSON. Add exposed filters for category and date range. Configure caching for 5 minutes.
FAQ
Mini Project
Goal: Build a complete content listing system using Views for a blog.
Create a page view:
/blogshowing published articles with:- Image thumbnail (100px wide)
- Title (linked to article)
- Summary (trimmed to 300 characters)
- Author name
- Published date
- Category tags
- Sorted by publish date, newest first
- 12 items per page with full pager
Add a sidebar block: "Recent Posts" showing:
- Last 5 articles
- Title only, linked
- No pager
Add exposed filters:
- Category dropdown (taxonomy)
- Date range (from/to)
Add a contextual filter:
/blog/{tag}showing articles filtered by tagAdd an RSS feed display at
/blog/feedwith 20 itemsAdd a REST export display at
/api/blogreturning JSONAdd caching: tag-based cache with 1 hour lifetime
What's Next
With Views mastered, learn how to manage images and media with the Media and Image Styles module. Then explore Revisions and Content Moderation for managing the content lifecycle.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro