A Minimal Jinja Template
n
n
This is a simple template that demonstrates a few basic Jinja concepts: a loop, a variable, and a comment. This code is a complete, runnable example of how to start using Jinja’s core features to create a dynamic web page.
nn
<!DOCTYPE html>n<html lang="en">n<head>n <title>My Webpage</title>n</head>n<body>n <ul id="navigation">n {% for item in navigation %}n <li><a href="{{ item.href }}">{{ item.caption }}</a></li>n {% endfor %}n </ul>nn <h1>My Webpage</h1>n <p>{{ a_variable }}</p>nn {# This is a comment that will not be rendered #}n</body>n</html>
n
Explanation of Components
n
- n
- {% for … %}: This is a tag that controls the flow of the template. The
forloop iterates over the `navigation` variable to generate a list of links. - {{ … }}: These are variables that are replaced with dynamic content when the template is rendered. In this example,
item.href,item.caption, anda_variableare placeholders for data. - {# … #}: This is a comment. Any text within these tags will be ignored by the Jinja engine and will not appear in the final HTML output.
n
n
n
n
n
