Use this to understand templating basics.
Template Fundamentals
Template fundamentals: separate the structure (template) from the data (variables), keep templates small and readable, and test the rendered output before deploying it.
1. Templates combine static text with variables and logic.
2. Fail on undefined variables (StrictUndefined).
3. Minimal logic in templates.
4. Consistent whitespace control.
5. Test with sample data.
variables → template engine → text
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as undefined values, unsafe escaping, implicit type conversion, environment-specific filters, secret exposure, whitespace-sensitive syntax and valid render producing invalid target configuration, choosing the cases most relevant to template/context contract, undefined handling, escaping, deterministic filters and parse/validation of rendered output before apply. For Templates → Template Fundamentals, the evidence must connect the control-plane result to the rendered configuration/document consumed by a downstream parser or service and explain any gap between desired, controller-reported and consumer-visible state.
Step 2 Common mistakes Narrow the fault
- Templates without tests.
Step 3 Where it fails Narrow the fault
Failure analysis for Templates → Template Fundamentals should follow the path through the components: template/context → expression evaluation → filters/tests → rendering/escaping → target parser → target apply → read-back.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Separate structure (template) from data (variables).
- Keep templates small.
- Test rendered output.
- Template + variables → output — model
- Strict undefined variables — fail on missing data
- Rendering tests — quality
ReferenceWhy it matters1 section · depth on demand
In depth
Templates separate the structure of generated text — configuration, reports, documents — from the data that fills it. One template per device role plus data per device produces hundreds of consistent configurations, and a change to the template updates all of them.
Core concepts:
| Concept | Jinja2 example |
|---|---|
| Variable | {{ hostname }} |
| Loop | {% for vlan in vlans %}…{% endfor %} |
| Condition | {% if role == 'core' %}…{% endif %} |
| Filter | upper, default, join applied with the pipe operator |
| Include/inheritance | {% include 'aaa.j2' %}, {% extends 'base.j2' %} |
| Whitespace control | {%- -%}, trim_blocks |
Keep logic minimal in templates, prepare data before rendering, fail on undefined variables, and test rendering in CI.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
Templates → Template Fundamentals is owned at runtime by the template engine rendering a versioned template with a bounded context and filter/function set. The linked authority for bounded mechanics is Jinja Documentation — Template Designer Documentation; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Templates > Template Fundamentals. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://jinja.palletsprojects.com/en/stable/templates/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For template/context contract, undefined handling, escaping, deterministic filters and parse/validation of rendered output before apply, prefer typed fields and stable IDs over human presentation text.