Headers and footers
Many applications have shared HTML at the top and bottom of most pages. Rather than repeating that markup in every view file, WebEngine can load special _header.html and _footer.html files automatically.
That keeps the shared framing consistent and reduces repeated HTML in the project.
How header and footer files work
Headers and footers are discovered by special filenames. A file such as page/_header.html is applied before the page view, and page/_footer.html is applied after it.
Those files can also appear in nested directories. For example, page/admin/_header.html applies within the /admin section. That makes it possible to give one area of the application its own framing while still keeping the project-wide layout elsewhere.
When several levels are involved, WebEngine assembles them in a predictable order so outer headers appear before inner ones, and inner footers appear before outer ones on the way back out.
Keeping a consistent header and footer throughout the application also helps the architecture stay simple. The page views can focus on page content while the common framing is handled in one place.
When to use them, when not to use them
Headers and footers are a good fit for:
- site-wide page chrome
- section navigation
- repeated metadata or framing content
They are less useful when the layout needs deeper composition rules. In that case page partials or custom HTML components may be a better fit.
There is also one hard rule to keep in mind: header and footer files should not be mixed with partial-based page inheritance in the same response. WebEngine treats those as two different layout techniques.
HTML can be reused and kept tidy with custom HTML components, and more advanced page layouts can be achieved with page partials.