Display content with views
Views builds dynamic content displays: listing pages, landing pages, and blocks that update as content changes. Thinking about views early in content modeling makes sure the displays you want are possible to build.
A content model whose fields support the listings you plan, and a view configuration for each listing: a filterable tour list, a region landing page, and a featured tours block.
Prerequisites
Section titled “Prerequisites”- A running Drupal CMS site and an account that can manage content types and views.
- Familiarity with how Drupal CMS structures content.
Plan how content will be reused
Section titled “Plan how content will be reused”Views can pull content from multiple content types and fields and display it in many formats and styles. List the displays you need before you settle the fields. For a wine tours site:
- A layout section on the home page with a block listing featured tours.
- A page listing all tours, filterable by region or category.
- A region-specific landing page showcasing tours within a particular area.
Then decide the details. Will one media image field suffice, resized with responsive image styles? Or do high-impact displays need more editorial control? You may want one image field for the hero image with precise dimension requirements, another for search-result thumbnails and listing displays, and possibly a third for social media cards.
Store data in filterable, sortable fields
Section titled “Store data in filterable, sortable fields”Views filters and sorts on fields, so the field type decides what a view can do:
- To let visitors sort tours by price, store the price as a numeric field rather than plain text.
- To let visitors filter tours by region, make the region a taxonomy term rather than a text field.
Category-type fields are strong candidates for filter criteria. Create a taxonomy vocabulary populated with terms, then add a reference field to the relevant content type. For example, create a Wine regions vocabulary with a term for each region, then add a Wine regions reference field to the Wine tours content type. You can then build a display that visitors filter by wine region.
Connect content with reference fields
Section titled “Connect content with reference fields”References let views connect different content types, such as linking testimonials to wine tours or showing the wineries associated with a region:
- A winery directory page can use a view that pulls from the Winery content type and filters by a wine region taxonomy term.
- Testimonials can include a reference to the related wine tour, enabling a view that shows the testimonials for a given tour.
Configure the tour listing page
Section titled “Configure the tour listing page”- Content model decisions: a Wine tour content type with fields for title, featured image, price, duration, region (taxonomy term), and tour category (taxonomy term).
- View configuration: filters for published status, region (exposed), and category (exposed); display as a grid of tours, sorted by title or price.
Configure the region landing page
Section titled “Configure the region landing page”- Content model decisions: a Wine region taxonomy, with Winery and Wine tour content that references it.
- View configuration: a contextual filter on the wine region term, with two sections: a list of wineries in the region, and a grid of tours in the region.
Configure the featured tours block
Section titled “Configure the featured tours block”- Content model decisions: a “Featured” checkbox field on the Wine tour content type.
- View configuration: a filter on the “Featured” field being checked; display as a list of tours with title and image, placed in a homepage block.
Verify
Section titled “Verify”- Visit the tour listing page, choose a region in the exposed filter, and confirm the list narrows to tours in that region.
- Mark a tour as featured, then confirm it appears in the featured tours block on the home page.
Related
Section titled “Related”- An example content model shows the full model these listings come from.
- Configure SEO and social sharing fields uses taxonomy-driven pages for SEO landing pages.
- Drupal User Guide, Chapter 9: Creating Listings with Views walks through building views step by step.
Was this page helpful?
Drupal is a registered trademark of Dries Buytaert.