Views (for Drupal 7)
views
A powerful query builder and display system for creating customized lists and presentations of content from your Drupal database.
Overview
The Views module provides a flexible method to control how lists and tables of content, users, taxonomy terms, and other data are presented on your Drupal site. Each individual 'view' is a custom query you design to fetch content from your database and display it in any format.
Views provides a graphical interface to build SQL queries without writing code. You can create page displays with URLs, blocks to place in regions, feeds for RSS output, and more. The module supports relationships between data types, exposed filters for user interaction, contextual filters (arguments), and extensive theming capabilities.
The Views system is highly extensible through handlers (for fields, filters, sorts, arguments, and relationships) and plugins (for displays, styles, rows, access control, caching, pagers, and queries). This makes it the foundation for many Drupal 7 modules and site building patterns.
Features
- Graphical query builder interface for creating database queries without SQL knowledge
- Multiple display types: Page (with URL and menu links), Block, Feed (RSS/Atom), Attachment, and Embed
- Flexible field handlers for displaying node, user, taxonomy, comment, and custom data with formatting options
- Filter handlers with exposed filters allowing site visitors to filter results dynamically
- Sort handlers with exposed sorting for user-controlled result ordering
- Contextual filters (arguments) for dynamic content based on URL parameters or other context
- Relationship handlers for joining related data (e.g., node author, taxonomy terms)
- Area handlers for header, footer, and empty text content with tokens and custom text
- Multiple style plugins: Unformatted list, HTML list, Grid, Table (with sortable columns), RSS
- Row plugins for rendering individual items as fields, full nodes, teasers, or custom formats
- AJAX support for paging and exposed filter refreshing without page reload
- Time-based caching for both query results and rendered output
- Access control via permissions or roles at the view/display level
- Live preview in the administrative interface with SQL query display and performance statistics
- Export/import of view configurations for deployment and sharing
- Extensive template override system with view-specific and display-specific suggestions
- Integration with 18 Drupal core modules (node, user, taxonomy, comment, field, etc.)
- Pager plugins: Full pager, Mini pager, fixed item count, or no pager
- Grouping support for organizing results by field values
- Contextual links integration for quick access to view editing
Use Cases
Content listing pages
Create pages displaying lists of content filtered by type, taxonomy terms, author, or date. Examples: blog listings, news archives, article indexes, product catalogs. Configure with Page display, exposed filters for user refinement, and paging for large result sets.
Sidebar blocks with recent/popular content
Build blocks showing recent posts, popular articles, upcoming events, or featured content. Use Block display with limited item count and no pager. Sort by date, view count, or sticky flag. Place in sidebar regions for supplementary navigation.
Administrative content management
Create administrative interfaces for managing content with bulk operations. Table format with sortable columns, exposed filters for content type and status, and edit/delete links. Integrate with Views Bulk Operations (VBO) module for mass actions.
User directories and member lists
Display user listings for community sites with user pictures, bios, and profile information. Filter by role, registration date, or custom profile fields. Create both public member directories and administrative user management views.
Taxonomy term pages
Replace default taxonomy term pages with custom views showing content tagged with specific terms. Add exposed filters for content type, date ranges, or authors. Display related terms or term hierarchies.
Related content blocks
Use contextual filters to create blocks showing content related to the currently viewed node. Relate by taxonomy terms, author, or custom relationships. Place on node pages to encourage further engagement.
RSS feeds and content syndication
Generate RSS/Atom feeds for content categories, user activity, or site-wide updates. Use Feed display with RSS style. Configure feed-specific fields like item title, link, and description.
Image galleries and portfolios
Create image galleries using Grid style with image fields. Add lightbox integration through companion modules. Support for multiple galleries, categorization, and slideshow views.
Event calendars and schedules
Display upcoming events in list, table, or calendar format. Filter by date ranges, event categories, or locations. Integrate with Date module for date field handling and calendar displays.
Search result pages
Create custom search result displays with more control than default Drupal search. Highlight search terms, show relevant metadata, and allow refinement through exposed filters.
E-commerce product listings
Build product catalog pages with filtering by category, price range, or attributes. Table or grid display with product images, prices, and add-to-cart links. Integrates with Commerce and Ubercart modules.
Reports and data dashboards
Create administrative reports showing content statistics, user activity, or custom data. Use aggregation for counts and totals. Table format with sorting and CSV export through companion modules.
Tips
- Use the Master display for settings shared across all displays, then override specific settings per display to avoid repetition.
- Enable 'Always show advanced display settings' in Views settings for easier access to relationships and contextual filters.
- Use the 'Preview with contextual filters' option to test views with different argument values.
- Clone existing views as a starting point rather than creating from scratch for similar use cases.
- Use field rewriting to create custom links, combine fields, or apply tokens to field output.
- Enable SQL query display during development to understand and debug the generated queries.
- Use grouped filters to create AND/OR filter combinations for complex filtering logic.
- Set meaningful administrative comments on views and displays for team documentation.
- Use the 'Exclude from display' option on fields that provide data for rewriting or sorting but shouldn't be shown.
- Test views with different user roles to ensure access settings work correctly across permission levels.
- Use Views UI keyboard shortcuts: Ctrl+Enter to save forms, Escape to close modal dialogs.
- Export views regularly as backup and for deployment between environments.
- Use semantic class names in CSS settings to facilitate theming and JavaScript targeting.
- Consider using Attachment displays to combine multiple views with shared exposed filters.
Dependencies
Related Projects
Full integration with content (nodes) including handlers for all node fields, status, publishing options, author, dates, revision information, and content type filtering.
Integration with user accounts including fields for username, email, roles, registration date, last access, and user pictures.
Complete taxonomy integration including term names, descriptions, vocabulary filtering, hierarchical depth, and term-node relationships.
Comment system integration with handlers for comment content, author, thread structure, and node comment statistics.
Field API integration automatically exposing all Field API fields to Views with appropriate handlers based on field type.
File system integration including file name, path, size, MIME type, and upload information.
Image field integration with image style support for generating thumbnails and styled images.
Integration with core search providing search keyword filtering, scoring, and result highlighting.
Node view statistics integration for sorting and filtering by view counts.
Book module integration for displaying book hierarchies and navigation.
Language and translation handlers for multilingual sites.
Node translation support for filtering and relating translated content.
Feed aggregator integration for displaying RSS feed items.
User contact link handler for displaying contact links in user views.
User activity tracking integration.
Legacy profile module field integration.
Poll module integration for displaying poll information.
Deep integration with Chaos Tools Suite for export/import, object caching, AJAX framework, and modal dialogs.
Admin Pages
| Title | Path | Description |
|---|---|---|
| Views | /admin/structure/views |
The main Views administration page displaying all available views organized into Enabled and Disabled groups. From this page you can add new views, enable/disable existing views, edit view configurations, clone views, export views, and delete views. Views can be filtered and sorted when the listing filters option is enabled. |
| Add new view | /admin/structure/views/add |
A wizard-style interface for quickly creating new views. You specify the basic settings and the wizard generates a starting configuration that you can then customize in the full editor. |
| Edit view | /admin/structure/views/view/%view_name/edit |
The full view editing interface with all configuration options. The interface is divided into sections for display settings, format/fields, filter criteria, sort criteria, contextual filters, relationships, and advanced options. Each display (Master, Page, Block, etc.) can be configured independently or inherit from the Master display. |
| Views Settings | /admin/structure/views/settings |
Global settings that affect all views and the Views UI behavior. |
| Views Settings - Advanced | /admin/structure/views/settings/advanced |
Advanced settings for debugging, caching, and localization. |
| Import view | /admin/structure/views/import |
Import a view from exported PHP code. Paste the exported view code and provide a name to import the view configuration. |
| Fields used in views | /admin/reports/fields/views-fields |
Shows a report of all fields and their usage across all views in the system. Useful for auditing field usage before removing fields. |
| Views plugins | /admin/reports/views-plugins |
Shows a report of all Views plugins (display, style, row, etc.) and which views are using them. Useful for understanding plugin usage across the site. |
Permissions
| Permission | Description |
|---|---|
|
Access the views administration pages to create, edit, enable, disable, and delete views. This is a powerful permission that should only be granted to trusted administrators. |
|
Bypass all access restrictions when viewing views. Users with this permission can see any view regardless of its access settings. Use with caution. |
Hooks
| Hook | Description |
|---|---|
hook_views_api |
Register your module as implementing the Views API. Required for Views to load your module's .views.inc file and recognize your handlers/plugins. |
hook_views_data |
Describe database tables and fields to Views, allowing them to be used in views. Define handlers for fields, filters, sorts, arguments, and relationships. |
hook_views_data_alter |
Alter Views data defined by other modules. Add fields to existing tables, modify handlers, or change relationships. |
hook_views_plugins |
Register custom plugins (display, style, row, argument default, argument validator, access, cache, pager, exposed form, localization, query, display extender). |
hook_views_plugins_alter |
Alter plugin definitions from other modules. |
hook_views_default_views |
Provide default views that ship with your module. Views can be enabled/disabled by site administrators. |
hook_views_default_views_alter |
Alter default views defined by other modules before they are cached. |
hook_views_pre_view |
Called at the very beginning of view processing (execute_display or preview). Allows altering the view before anything is done. |
hook_views_pre_build |
Called after display pre_execute but before the query build process. Useful for modifying the view before query construction. |
hook_views_post_build |
Called right after the build process. The query is fully built but not yet executed. |
hook_views_pre_execute |
Called right before query execution. Last chance to modify the query. |
hook_views_post_execute |
Called right after query execution. Results are available but pre_render has not run. |
hook_views_pre_render |
Called right before rendering. Pre_render has completed for handlers, all data is available. |
hook_views_post_render |
Called after rendering is complete. Allows post-processing of rendered output. |
hook_views_query_alter |
Alter the query before execution. Allows direct manipulation of query conditions, joins, and other elements. |
hook_views_query_substitutions |
Provide placeholder substitutions for use in view queries. Placeholders like ***CURRENT_USER*** are replaced at query time. |
hook_views_invalidate_cache |
Respond to Views cache being cleared. Fired when views are created, updated, deleted, enabled, or disabled. |
hook_views_view_presave |
Alter a view just before it is saved to the database. |
hook_views_view_save |
Respond to a view being saved. |
hook_views_view_delete |
Respond to a view being deleted or reverted. |
hook_views_ajax_data_alter |
Alter the AJAX commands returned by a Views AJAX request. |
hook_field_views_data |
Override the default views data for a Field API field type. Called for the module that defines the field type. |
hook_field_views_data_alter |
Alter views data for a single Field API field after default data is generated. |
Drush Commands
| Command | Description |
|---|---|
|
Revert overridden views to their default (code-defined) state. If no view names specified, shows a list of overridden views to choose from. |
|
List all views in the system with their status, type, and tags. Can filter by various criteria. |
|
Enable the specified views |
|
Disable the specified views |
|
Configure Views settings for development. Enables SQL query display, performance statistics, disables live preview auto-update, and enables debug output. |
|
Analyze all views and report potential problems. Checks for common configuration issues and displays warnings. |
|
Clear Views-specific caches including views data cache and block cache. |
Troubleshooting
Check filter criteria, especially published status and access permissions. Enable query preview to see the generated SQL. Verify the base table has data. Check that exposed filter values are not excluding all results.
Ensure 'Use AJAX' is enabled in the display settings. Verify JavaScript has no errors in browser console. Check that the view has a unique DOM ID. Clear Views and page caches.
Enable 'Distinct' in query settings (Advanced > Query settings). Check for relationships that might create multiple rows. Use aggregation if grouping is needed.
Configure the 'Label for Any value' in Views settings (/admin/structure/views/settings). Each exposed filter can also override this in its settings.
Enable caching (time-based) in advanced settings. Add database indexes for filtered/sorted fields. Limit fields retrieved. Use 'Render pager' only when needed. Check for expensive relationships.
Clear theme registry cache (drush cc theme-registry). Verify template naming follows pattern: views-view--[view-name]--[display-id].tpl.php. Check template is in active theme directory.
Check display access settings (None/Role/Permission). Verify user has required permission or role. Check that 'access content' permission is granted if displaying nodes.
Ensure block is placed in a region at /admin/structure/block. Check block visibility settings (pages, roles, content types). Verify the view is enabled and the block display exists.
Check URL structure matches argument position. Configure 'Default value' for when argument is missing. Use 'Provide default value > Content ID from URL' for node pages.
Click 'Save' on the view edit page (changes are not auto-saved). Clear Views cache with 'drush cc views'. Check for locked views if multiple users edit simultaneously.
Security Notes
- Grant 'Administer views' permission only to highly trusted roles, as it allows creating PHP-based arguments and filters.
- The 'Bypass views access control' permission is dangerous and should rarely be assigned outside development.
- Avoid using PHP code plugins (argument default, argument validator) in production - use custom handlers instead.
- Views respects node access permissions when displaying content, but verify with different user roles.
- Exposed filters can reveal sensitive field values in dropdowns - consider access implications.
- SQL injection is prevented by the query builder, but custom query alterations should use proper placeholders.
- Block views may bypass node access if not configured correctly - verify access settings on block displays.
- Feed displays may expose content to anonymous users regardless of node access settings.
- View exports contain configuration only, but review before importing views from untrusted sources.