Skip to content

How-to guideFor site buildersDrupal CMS 2

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.

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.

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.

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.
  • 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.
  • 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.
  • 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.
  • 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.

Was this page helpful?

Drupal is a registered trademark of Dries Buytaert.