Layout Builder is Drupal core’s visual layout management system that allows administrators and site builders to control page structure using sections and blocks without writing custom templates. In Drupal 10 and 11, Layout Builder integrates with entities, blocks, fields, render arrays, caching, and Twig. It provides a structured way to manage layout while still respecting Drupal’s rendering pipeline. Understanding Layout Builder deeply requires knowledge of sections, block plugins, custom layouts, overrides, caching behavior, and how Twig interacts with layout templates. In enterprise Drupal environments, Layout Builder enables scalable, reusable page architecture while preserving developer control.
1. Core Architecture
Layout Builder consists of:
- Sections
- Layout plugins
- Blocks (field blocks or custom blocks)
- Overrides per entity
Two usage modes:
- Layout per content type (default layout)
- Layout overrides per individual node
Enable module:
drush en layout_builder -y
2. Sections and Layout Plugins
A section contains:
- Layout (one column, two column, etc.)
- Blocks placed inside regions
Core layout plugins:
- One column
- Two column
- Three column
These are defined as Layout plugins.
3. Creating Custom Layout Plugin
Create a custom module:
weeklydrupal_layout/
Define layout in:
weeklydrupal_layout.layouts.yml
Example:
two_column_hero:
label: 'Two Column Hero'
path: layouts/two-column-hero
template: two-column-hero
category: 'Custom'
default_region: content
regions:
left:
label: Left
right:
label: Right
Create template:
layouts/two-column-hero/two-column-hero.html.twig
Example Twig:
<div class="wd-layout wd-layout--two-column">
<div class="wd-layout__left">
{{ content.left }}
</div>
<div class="wd-layout__right">
{{ content.right }}
</div>
</div>
Clear cache to register layout.
4. Block Plugins in Layout Builder
Layout Builder uses Block plugins.
Types of blocks:
- Field blocks (entity fields)
- Custom block content
- Views blocks
- Custom block plugins
5. Creating Custom Block Plugin
Inside custom module:
src/Plugin/Block/HeroBlock.php
Example:
namespace Drupal\weeklydrupal_layout\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* @Block(
* id = "weeklydrupal_hero_block",
* admin_label = @Translation("WeeklyDrupal Hero Block")
* )
*/
class HeroBlock extends BlockBase {
public function build() {
return [
'#markup' => '<div class="hero-block">Hero Content</div>',
];
}
}
This block becomes available inside Layout Builder.
6. Layout Overrides per Node
When overrides are enabled:
- Each node can have a unique layout
- Blocks are stored in layout sections
Important:
Overrides increase flexibility but may increase maintenance complexity.
7. Twig Overrides for Layout Builder
Layout Builder templates can be overridden.
Examples:
layout-builder.html.twig
layout-builder-section.html.twig
block--layout-builder.html.twig
Override inside theme templates folder.
Always use render arrays when printing regions:
{{ content }}
8. Preprocess with Layout Builder
Example:
function weeklydrupal_theme_preprocess_layout(&$variables) {
$variables['attributes']['class'][] = 'wd-layout-builder';
}
Keep preprocess logic presentation-focused.
9. Cache Considerations
Layout Builder interacts with:
- Render cache
- Dynamic page cache
- Block cache
Each block carries cache metadata.
When building custom blocks:
public function getCacheContexts() {
return ['user.roles'];
}
Improper cache handling can cause:
- Incorrect block rendering
- Role-based content leakage
10. Performance Strategy
Best practices:
- Avoid too many nested blocks
- Use reusable blocks
- Avoid heavy logic in block build()
- Use services for complex logic
11. Layout Builder vs Paragraphs
Layout Builder:
- Controls structure
- Section-based
- Block-based
Paragraphs:
- Controls reusable content components
- Entity-based
Enterprise approach:
- Layout Builder defines page structure
- Paragraphs define structured content
12. Advanced Enterprise Pattern
Common large-site strategy:
- Custom layout plugins
- Design system-aligned components
- Block plugins wrapping reusable services
- CDN + aggressive caching
- No inline markup logic
This ensures scalable architecture.
Common Mistakes
- Heavy logic inside block build()
- Ignoring cache metadata
- Overusing per-node overrides
- Mixing layout and business logic
- Not documenting layout usage rules
Interview Questions (Frontend Drupal)
1. What is Layout Builder?
Expected Answer:
A Drupal core module that allows section-based layout management using blocks and layout plugins.
2. What is the difference between default layout and layout override?
Expected Answer:
Default layout applies to all entities of a type; override allows per-entity layout customization.
3. How do you create a custom layout?
Expected Answer:
Define it in a .layouts.yml file and provide a Twig template for regions.
4. How do custom block plugins integrate with Layout Builder?
Expected Answer:
Block plugins become available as blocks that can be placed inside layout sections.
5. Why is cache metadata important in block plugins?
Expected Answer:
Because layout sections and blocks are cached, and incorrect cache contexts can cause wrong content rendering.
6. How does Layout Builder align with component-driven architecture?
Expected Answer:
It structures sections while components (blocks/paragraphs) handle reusable UI pieces.