Pug Template Inheritance: Reduce HTML Duplication with Extends and Blocks
Learn how Pug's extends and block directives let you share layout markup across pages, avoid duplication, and keep server‑side rendering clean.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn how Pug's extends and block directives let you share layout markup across pages, avoid duplication, and keep server‑side rendering clean.
When Contao projects grow, mixing PHP and HTML in templates creates maintenance debt. This architecture note explains how Twig enforces boundaries, the smallest safe override, and how to verify cache and debug behavior.
An architecture note on designing Pug template inheritance with extends and block directives, constraining include paths, and maintaining cache and escaping discipline.
Use Pug extends and block to inherit a shared HTML layout and override only the parts that change.
Use Pug extends and block to share layouts without duplicating markup, but verify your Pug version—append and prepend behavior changed between releases.
Learn how to diagnose and fix common Pug template inheritance problems such as blocks not overriding, duplicate block errors, and extends resolution failures.
Learn how to use Pug’s extends and block features to reuse layouts, see a worked example, and avoid common indentation pitfalls.
Pug’s template inheritance lets you write a single base layout and extend it across pages, reducing duplication and keeping rendering fast. Learn the syntax, practical examples, performance benefits, and common pitfalls in this concise guide.
Centralize your HTML skeleton in one Pug layout and let child templates override named blocks — including append/prepend for additive changes and multi-level section layouts.