Customizing the display output of content
Drupal provides display view modes that allow you to customize the fields and other properties attached to an entity. In this recipe, we will adjust the teaser display mode of an Article
content type. Each field or property has controls for displaying the label, the format to display the information in, and additional settings for the format.
Harnessing view displays allows you to have full control over how content is viewed on your Drupal site.
How to do it…
- Now, it is time to customize the form display mode by navigating to Structure and then Content Types.
- We will modify the
Article
content type’s display. Click on the drop button arrow and select Manage display. - Click on the Teaser view mode option to modify it. Teaser view mode is used in node listings, such as the default home page.
- Drag the Tags field to the hidden section. The tags on an article will no longer be displayed when viewing a Teaser view mode.
- Click on the settings cog icon for the Body field to adjust the trimmed limit. The trim limit is a fallback for the summary or trimmed format when the summary of a text-area field is not provided. Modify this by changing it from
600
to300
. - Click on Save to save all the changes that you have made.
- View the home page and review the changes that have taken effect.
How it works…
The default rendering system for an entity uses view displays. View display modes are configuration entities. Since view display modes are configuration entities, they can be exported using configuration management.
When a content entity is rendered, the view display goes through each field formatter configured in the display. The field formatter is the option chosen from the Format property of the Manage Display form and identifies what code should be used to render the field value. The field value is retrieved from the entity and passed to the field formatter plugin that has been instantiated with the configuration provided to the view display. This collection of render data is then passed through the rest of Drupal’s render pipeline.
There’s more…
We will discuss more items for managing the form of a content entity in the following section.
Managing view display modes
Additional form display modes can be added by visiting Structure and then Display Modes under View Modes. Each content entity type has a hidden default view mode that always exists. Additional view display modes can be added and configured using the display management form.
These view modes can then be leveraged when displaying content with views, the Rendered entity field formatter for entity references, or when rendering entities with custom code.