Including Partials
Partials are reusable template fragments.
Examples:
- navbars
- footers
- alerts
- “card” components
flowchart LR
subgraph extends
E1["child says: put ME inside base"] --> E2["base renders, child fills the blocks"]
E2 --> E3["one per template, at the top"]
end
subgraph include
I1["page says: paste THIS here"] --> I2["the partial renders in place"]
I2 --> I3["as many as you like, anywhere"]
end
E3 -.->|"layout"| K["a page shape shared by many pages"]
I3 -.->|"reuse"| L["a card, a nav bar, a form row"]
Create a partial
Section titled “Create a partial”templates/partials/_navbar.html:
<nav>
<a href="{{ url_for('home') }}">Home</a>
<a href="{{ url_for('about') }}">About</a>
</nav>Include it in another template
Section titled “Include it in another template”{% include "partials/_navbar.html" %}Where to use includes
Section titled “Where to use includes”- inside
base.htmlto share nav/footer - in pages to share repeated UI patterns
Tip: naming convention
Section titled “Tip: naming convention”Many teams prefix partials with _ (like _navbar.html) to signal “not a full page”.
Jinja doesn’t require it, but it helps humans.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading