Layouts are considered the foundation for Salla theme, through which all of the theme pages will share the same layout. When building a Salla theme, you will need to start by planing for your layouts, so then you can use them to unify your pages' look-and-feel.📙 What you'll learn about#
Locate Layout files#
Master layout hooks#
Most of the theme hooks are used within the master layout. This is due to the fact that this layout, which can be overwritten by the developer, is used across all of the website pages. It means that all of the hooks' contents will be injected into all of the website pages.Using layouts#
As we saw in the Twig basic syntax, template inheritance is one of twigs perks; it allows you to set a base code that contains all of the elements for your website and define blocks that can override from child templates.Inheritance is the main concept of building layouts. The developer starts by creating an HTML page with the overall skeleton of the theme pages, with creating blocks
inside it for future content. These future contents will be filled by the page that will inherit this layout page.Embed theme pages within the layout.#
In order to embed the theme pages within the layout page, first we need to extend, inherit, the layout page. In the following example, we have a mylayout.twig
file where we define three blocks: head
, title
and footer
.To embed the theme pages within this layout, we start by extending them. Then we will enject the content into the defined three blocks: head
, title
and footer
.Build a new layout#
Building layouts is easy with Twilight; we simply need to create any new layout file inside the folder src\views\layouts\
. This step will make the layout available throughout the theme pages.Note that all of the new files are nothing but *.twig
files.
The main two steps for building layouts are:Create an HTML file, with the extension *.twig
, that contains the main skeleton of your theme with creating blocks
inside it for future contents.
Extend this layout page inside your theme's pages, and enject the content within the predefined blocks
.