Template inheritance vs. mixins for shared layout fragments in Pug
0 reputation · 21 Oct 2020, 19:10 UTC
When building a site with Pug, the team needs a single source of truth for recurring page sections such as headers, footers, and navigation bars.
Template inheritance provides explicit blocks that children fill, but nested block definitions can create ambiguous injection points, and the whitespace‑sensitive syntax may add unwanted line breaks. Mixins encapsulate markup with arguments, yet they accept arbitrary JavaScript expressions, raising injection concerns if data is not escaped, and they behave differently under runtime compilation versus build‑time rendering.
Which approach yields more predictable output when nested blocks are involved? How does each method behave under runtime compilation in the browser? What are the maintenance implications for a large codebase?