This document tries to answer all important questions about Jinja.
Jinja is a text-based template language similar to
cheetah and
Smarty.
The syntax and parts of the code were taken from the
Django template
language.
Jinja shouldn't be limited to XML, HTML or similar languages building up upon XML. There are many XML template languages out there (Kid, simpleTAL...) but all lack a simple syntax.
Like the Django templates, Jinja tries to simplify templating but provide a powerful syntax. The idea is to remove all application logic from the template. That sounds limited, but you should have a look at the example below to see the power behind the system.
Here is a small example how Jinja looks like:
<html>
<head>
<title>{{ page.title|default "untitled"|xmlescape }}</title>
</head>
<body>
{% if page.title %}<h1>{{ page.title|xmlescape }}</h1>{% endif %}
{% for section in page.sections %}
<h2>{{ section.title|xmlescape }}</h2>
<div class="text">
{{section.text|xmlescape|nl2pbr }}
</div>
{% endfor %}
{% if not page.sections %}
<div class="error">There are no sections on the page.</div>
{% endif %}
</body>
</html>
And this would be a nice text/plain example:
+-{% for char in page.title %}-{% endfor %}-+
| {{ page.title }} |
+-{% for char in page.title %}-{% endfor %}-+
{% for section in page.sections %}
{{ section.title }}
{% for char in section.title %}-{% endfor %}
{{ section.text|wordwrap 70|indent 4 }}
{% endfor %}
And here the rendered version of the text example:
+----------------------------+
| Frequently Asked Questions |
+----------------------------+
What is Jinja?
--------------
Jinja is a text-based template language similar to cheetah and Smarty.
The syntax and parts of the code where taken from the Django template
language.
Why not XML?
------------
Jinja shouldn't be limited to XML, HTML or similar languages building
up upon XML. There are many XML template languages out there (Kid,
simpleTAL...) but all lack a simple syntax.
Philosophy
----------
Like the Django templates, Jinja tries to simplify templating but
provide a powerful syntax. The idea is to remove all application logic
from the template. That sounds limited, but you should have a look at
the example below to see the power behind the system.