Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 37 ยท Views and Blocks

Menus and Layout Builder

Build navigation with Drupal menus, menu links and URL aliases, then design page layouts visually with Layout Builder sections, blocks and per-content overrides.

Visitors find content through navigation, and editors want to shape pages without waiting for a developer. Drupal answers both needs with two core features: menus for structured navigation, and Layout Builder for visual page layouts. This closing lesson of the chapter ties together blocks, Views and display settings.

A menu is a tree of links. Core provides several: Main navigation, Footer, Administration, Tools and User account menu. Create your own at Structure > Menus > Add menu.

You can add links in three ways:

  1. On the menu page: Add link with a title, a link target (a path or content autocomplete) and options like Show as expanded and Enabled.
  2. From the content form: in the sidebar's Menu settings, tick Provide a menu link, choose the parent. Available only for content types you allow under the content type's menu settings.
  3. In a module's *.links.menu.yml for links your code provides:
YAML
# greetings.links.menu.yml
greetings.hello:
  title: 'Hello'
  route_name: greetings.hello
  route_parameters:
    name: 'friend'
  menu_name: main
  weight: 10

Menu links in a module refer to route names, so they survive path changes.

Showing a menu

A menu appears on the page through a menu block placed in a region (see Blocks and Regions). In the block settings you choose the menu levels to show (initial level, number of levels), and whether to expand all children. The theme's Twig template renders the nested list; styling makes it a dropdown or a mobile menu.

For admin dropdowns, the contributed Admin Toolbar module helps editors work faster.

Paths and aliases

By default, a node lives at /node/5. The core Path module lets editors enter an alias such as /events/open-day, shown under URL alias in the content form. For automatic aliases, the contributed Pathauto module generates patterns like /events/[node:title]. Aliases improve readability and search results, and Drupal translates the alias to the internal path when routing.

Be consistent: change a pattern only before launch, or create redirects with the Redirect module so old URLs keep working.

Drupal builds breadcrumbs from the URL path. For better ones, use the Easy Breadcrumb module or write your own breadcrumb builder service. Breadcrumbs help navigation and are part of SEO structured data.

Layout Builder

Layout Builder (core, off by default) lets you arrange fields and blocks in sections with columns. Turn it on by enabling the Layout Builder (and optionally Layout Discovery) modules, then edit a content type's Manage display and tick Use Layout Builder.

You then see a visual page where you can:

  • Add a section (one column, two columns 50/50, three columns, 25/75, and so on).
  • Add a block to any section region: field blocks (the node's title, body, image), custom blocks, Views blocks, menu blocks.
  • Configure or remove a block, and drag to reorder.
  • Preview the page with real content, and toggle Show content preview.

Two levels of customization exist:

  1. Defaults: one layout shared by every node of the type.
  2. Overrides: tick Allow each content item to have its layout customized, and editors can alter an individual node through a Layout tab. Overrides are stored per node.
flowchart TD
    D["Content type default layout"] --> N1["Node A uses default"]
    D --> N2["Node B has an override"]
    N2 --> S["Sections: one column, then two columns"]
    S --> B["Blocks: title, image, body, related Views block"]

Defaults give consistency, overrides give flexibility.

When to use which

Need Use
Same layout everywhere, site-wide Block layout (regions in the theme)
Layout per content type Layout Builder defaults
Unique landing pages Layout Builder overrides
Pixel-exact designs Custom theme and Twig templates

A tip: Layout Builder gives editors great freedom, and freedom needs rules. Limit it with permissions (Configure any layout), restrict which blocks are available, and train editors. Complex overrides on thousands of nodes can complicate later redesigns.

Layout data as a stand-in

Layout Builder stores an ordered list of sections, each with a layout ID and components (blocks with a region and weight). The stand-in turns that structure into an outline of the page.

JS Stand-in: sections, regions and components

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Back to menus. A menu is a tree, and a menu block selects levels from it. This stand-in builds a nested list from flat link records with parents and weights, then limits the depth like the block settings do.

JS Stand-in: building a menu tree with depth limit

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Change maxDepth to 3 to reveal the deepest link.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does a module-provided menu link refer to its destination?

    links.menu.yml entries use route_name, so links stay valid if paths change.
  2. 2. What does the Pathauto module do?

    Pathauto builds readable aliases such as /events/open-day from tokens.
  3. 3. Where do you enable Layout Builder for a content type?

    Tick 'Use Layout Builder' under Manage display, after enabling the module.
  4. 4. What is the difference between Layout Builder defaults and overrides?

    Defaults give consistency per content type; overrides customize one node.

Summary

  • Menus are trees of links, edited in the UI or defined in modules by route name, and shown with menu blocks.
  • URL aliases (with Pathauto) make friendly paths; keep redirects for changed URLs.
  • Layout Builder arranges sections, regions and blocks visually, with defaults per type and per-node overrides.
  • Choose between regions, Layout Builder and custom Twig depending on how unique each page must be.

Next: Theme Structure and the Info File