Reader small image

You're reading from  Drupal 10 Masterclass

Product typeBook
Published inDec 2023
PublisherPackt
ISBN-139781837633104
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Adam Bergstein
Adam Bergstein
author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein

Right arrow

Drupal Views
and Display Modes

Drupal has a feature called Views that helps deliver dynamic content displays. This is one of the more popular features of Drupal, as it allows site builders to take existing structured content and reuse it in additional ways. This helps content authors avoid duplicating the same content that may be delivered in multiple places throughout a Drupal application. This chapter helps define Views, covers its features, and walks through how to use the feature. The chapter also touches on a complementary feature called display modes, integrated with Views. The combination of these two features empowers site builders to address a large number of use cases with little or no code. While complex, the chapter will address the purpose, offer hands-on development with these features, and provide the foundation to build more advanced use cases.

In this chapter, we’re going to cover the following main topics:

  • Defining Views
  • Defining display modes...

Defining Views

Views, as a feature, is one of the most compelling and most complex features for site builders. It is in core, which means it is out of the box with Drupal. At a high level, it is a dynamic display builder. Being able to learn and leverage its features effectively is not easy, but the results can be empowering.

Overview

Defining Views is tricky. It is important to dissect this definition significantly more.

The term display in this context has a broad definition. Drupal maintains structured content, which can be used within any display. In a traditional sense, content management systems (CMSs) store content that then gets displayed like a page on a website. Even Drupal does this with content types, nodes, and rendering nodes. However, recall earlier chapters where the problem of content duplication could be addressed by CMSs in favor of copying the same content repeatedly and pushing the burden onto content managers to do a lot of manual work. At a high level...

Defining display modes

Drupal’s display modes feature takes a different approach to creating displays and is complementary to Views. Conventionally, this feature starts with being able to control display settings for a content-type rendering on a page. However, additional display modes can be configured to display the same content in different ways as needed.

Overview

Display modes look at displays tied to a content type. A content type defines structured content. The same node within a content type can be displayed in different ways. Each display may be able to fine-tune which fields are displayed, labels, formats of field values, ordering of fields, and more. A content type can have as many display modes as needed to address any desired use case. Each content type can select a default display mode, which is most commonly used for rendering nodes.

This may be confusing concerning Views, given Views also allows for the building of displays. Display modes only define...

Using Views and display modes

Using Views is one of the more difficult tasks for site builders given its vast configuration options. While this chapter affords hands-on options, it is important to explore the feature in greater depth and to get more practice with time.

All the following examples leverage a blog content type with a primary use case of building different blog-related displays in the Drupal application. For the sake of clarity, the content type has fields for title, body, featured, and a banner image. Also, it’s assumed the Views UI module is enabled for the next screenshots and that a user is logged in with the correct permissions.

Creating a teaser display mode for blogs

An effective teaser could be as simple as a title of the blog linked to the full page with some preliminary, summarized body content.

Follow these instructions to create a teaser:

  1. A teaser display mode can be created by going to Administration | Structure | Display modes ...

Summary

Views help provide a robust, feature-rich dynamic display tool for site builders. Its ability to configure features across different types of displays, structured content, and other Drupal features helps Views reuse the same content in different displays and feed-based formats. Display modes help complement Views for displays directly integrated with content types. The combination of both offers two highly flexible tools capable of addressing a large number of use cases.

The next chapter presents media and files that help Drupal manage and deliver static digital assets.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Drupal 10 Masterclass
Published in: Dec 2023Publisher: PacktISBN-13: 9781837633104
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein