Pug Tutorial: Compile Indented Templates and Pass Explicit Locals

Pug turns indentation-based template source into output such as HTML. Follow the nesting of one small page, then pass a defined locals object and extract a reusable layout. Because indentation carries structure, template readability and escaping behavior matter as much as getting one successful rendered response.

Here's a popular Pug video — watch it, then summarize it with one click. Or paste any other YouTube link below.

— or paste your own YouTube link —

Want to keep the key points from a YouTube video? Paste the link below to turn it into structured notes.

Why Use Pug Tutorial: Compile Indented Templates and Pass Explicit Locals

Frequently Asked Questions

Why can indentation change the generated HTML structure?

Pug uses indentation to express nesting rather than relying only on explicit closing tags. A misplaced level can move elements under a different parent even when the visible source still looks superficially similar.

Does rendering a missing local always produce useful content?

A template depends on the context it receives and the expressions it evaluates. Define required locals and handle optional values deliberately instead of accepting accidental blank sections or runtime errors.

How does a layout differ from copying a page shell?

A layout establishes reusable structure with designated extension points. This keeps shared document regions coordinated while individual views supply their own content instead of maintaining several diverging copies.

Should a template query the database inside its presentation loop?

Prepare the necessary records before rendering and keep storage coordination outside the view. Hidden queries complicate error handling and make a visual template unexpectedly responsible for application data access.

Why distinguish escaped interpolation from unescaped output?

Escaping affects whether a supplied value is treated as literal content or interpreted markup. Choose the operation according to the source's trust and destination rather than bypassing escaping to fix appearance casually.