Last updated September 16, 2020

When building a site using Drupal 8 and Drupal 9 Layout Builder, it's a good idea to keep the number of layout plugins manageable. In many cases it's better to create a single layout plugin that can be re-used rather than duplicate a layout multiple times to accommodate minor variations. One way to do this is provide editors with configuration options that will change the output when a layout is used.

For example, imagine you need to provide variations of a 3-column layout where the columns are different widths. You could define a new layout for each variation. Or you could define a single layout with a configuration option that allows a user to choose the column widths. The latter approach reduces code duplication, and makes the codebase easier to maintain.

In this tutorial we'll:

  • Learn how to declare advance layout plugins with configurable settings in the Drupal Layout Builder
  • Extend the LayoutDefault class and create a custom settings form that editors will see when using a layout
  • Use the provided configuration values in the layout's Twig template file to modify the layout when it is rendered

By the end of this tutorial you should be able to expose layout-related settings to editors, allowing for more flexibility in custom layout plugins.