
Drupal 10 Development Cookbook
By :

The Layout Builder
module allows content creators to use a drag-and-drop interface to customize how content is displayed on a page. Unlike using field formatters in view display modes, this does not require a developer and can be customized for individual pieces of content. With Layout Builder
, content creators select from different layouts available in the system and place blocks in them to build the page’s content. In this recipe, we will walk through installing Layout Builder
and setting up the layout for the Article
content type.
In this recipe, we will be using the standard installation, which provides the Article
content type. Any content type will suffice.
Layout Builder
module and its dependent module, Layout Discovery
:php vendor/bin/drush en layout_builder –yes
Layout Builder
for the display mode of our content type. Visit Structure and then Content Types and use the drop button for Article to click Manage Display.Layout Builder
user interface to customize the Article layout.The Layout Builder
module provides an alternative render system for entity types. Using Layout Builder
is an opt-in process for each display mode of a content entity type. If the entity type’s display mode is not managed by Layout Builder
, it falls back to the regular render system using field formatters.
Layouts are provided by layout plugins, which have matching Twig templates. Modules and themes can define new templates that can be used. Layout Builder
leverages blocks to display content. The kinds of blocks available to be embedded in Layout Builder
are based on blocks available to the system.
Layout Builder
also exposes each field on the content entity as a block, allowing you to place each field in a different section.
Like custom nodes or other entity templates, if you make changes to the layout plugin or nested elements without updating the corresponding Twig templates for the layout, you may see things render incorrectly. Be sure to review the Twig template accordingly when making such changes.
Layout Builder
was an exciting addition to Drupal when it first arrived and has many more features and customizations far beyond what was covered in this recipe.
The Layout Builder
user interface went through rigorous accessibility testing. The entire Layout Builder
user interface can be navigated using a keyboard or other accessibility devices.
When configuring the layout options, the Allow each content item to have its layout customized option allows content editors to override the default layout for their content. When a piece of content is created, it will use the default layout. Content editors will see a Layout tab that allows them to customize the display of their content in the Layout Builder
user interface.
The layout override is also stored in field data attached to the content entity, making it tracked with revisions! That means new drafts can be created for a piece of content with layout changes and they can be published through Content
Moderation
workflows.
There are a copious number of modules that extend Layout Builder
to customize its experience and provide default layouts. For instance, if you use the Bootstrap front-end framework, the Bootstrap Layout Builder (https://www.drupal.org/project/bootstrap_layout_builder) module provides a user interface for building layouts that use Bootstrap’s styling.
A list of modules that extend Layout Builder
can be found on Drupal.org
: https://www.drupal.org/docs/8/core/modules/layout-builder/additional-modules.
Drupal.org
: https://www.drupal.org/docs/8/core/modules/layout-builder