Last updated September 3, 2020

Layout plugins can be dynamically generated based on configuration using plugin derivatives. This allows developers to provide Drupal site administrators with a UI for creating new layout plugins, or to automatically register layout plugins based on the environment.

This is useful in situations where it's not enough to define a set of pre-configured layouts to use in the Layout Builder. Instead, you need to empower editors to declare their own new layout plugins without writing any code. Derivatives could also be used in scenarios where the layouts that should be made available depend on configuration set elsewhere in the module. Or, you might have a scenario where you want to have multiple different 2-column layouts, and for those layouts to have different names, so that they can be themed differently depending on which one is used.

In this tutorial we'll:

  • Create a user interface that allows editors to dynamically define layouts via configuration.
  • Learn how to set up a plugin deriver that creates layout plugins based on configuration.
  • Create custom dynamic layout plugins with variable numbers of columns.

By the end of this tutorial you'll know how to declare dynamic custom layout plugins using derivatives.