When designing a custom theme in Drupal 10, one of the most fundamental components is creating a custom header and footer. While these elements are essential for site branding and user navigation, understanding the best way to implement them in Drupal can be a bit confusing—especially when deciding between two options: using {{ page.header }}
or including a custom Twig template with {% include %}
.
In this tutorial, we’ll walk through how to create a custom header and footer, explaining when and why you might use either method to render content in your theme. We’ll also dive into how both approaches—{{ page.header }}
and {% include '@acesoftech/layout/header.html.twig' %}
—work, and how to decide which one fits your needs.
1. Creating a Custom Header and Footer in Drupal 10/11
Before we dive into the code and templates, let’s take a look at how Drupal organizes the structure of pages and regions.
Step 1: Define Regions in acesoftech.info.yml
In Drupal, regions are areas where you can place content, such as blocks, views, and other dynamic elements. To set up your custom header and footer, you first need to define these regions in your theme’s acesoftech.info.yml
file.
Open the acesoftech.info.yml
file, and add header
and footer
regions like this: