blob: a354486519557158d246e71a78af4abf07117cec [file] [log] [blame]
<% extends 'layout/base.tmpl' %>
<% set title = 'Index' %>
<% set active_page = 'index' %>
<% block content %>
<h1>Jinja Templates</h1>
<p>
Jinja is a
<a href="http://en.wikipedia.org/wiki/Sandbox_%28computer_security%29">sandboxed</a>
template engine written in pure <a href="http://www.python.org/">Python</a>. It
provides a <a href="http://www.djangoproject.com/">Django</a>-like non-XML syntax
and compiles templates into executable python code. It's basically a combination
of Django templates and python code.
</p>
<h2>Nutshell</h2>
<% filter pygmentize('html+jinja') %>
{% extends 'base.html' %}
{% block title %}Memberlist{% endblock %}
{% block content %}
<ul>
{% for user in users %}
<li><a href="{{ user.url|e }}">{{ user.username|e }}</a></li>
{% endfor %}
</ul>
{% endblock %}
<% endfilter %>
<h2>Philosphy</h2>
<p>
Application logic is for the controller but don't try to make the live for the
template designer too hard by giving him too less functionality.
</p>
<h2>Features</h2>
<ul>
<li><strong>Simple API</strong>. For basic usage just one function is needed:
<% filter pygmentize('python') %>
from jinja import from_string
print from_string('Hello {{ data }}!').render(data='World')
<% endfilter %></li>
<li><strong>Sandboxed</strong>. The whole engine is completely sandboxed. A
template designer won't be able to modify application data or execute
dangerous code.</li>
<li><strong>Python expressions</strong>. You can use nearly every python
expression. Not supported are the binary operators and list comprehensions /
generator expressions.</li>
<li><strong>Inheritance</strong>. Jinja uses the same concept for inheritance
Django uses. It's very powerful and easy to understand.</li>
<li><strong>Macros</strong>. Jinja provides so called macros that allow you to
put often used template snippets into callable blocks:
<% filter pygmentize('html+jinja') %>
{% macro dialog title, text %}
<div class="dialog">
<h2 class="title">{{ title }}</h2>
<div class="text">{{ text }}</div>
</div>
{% endmacro %}
<% endfilter %>You can then use this block by calling it:
<% filter pygmentize('html+jinja') %>
{{ dialog('Notification', 'Here the text for the macro.') }}
<% endfilter %></li>
<li><strong>Designer friendly</strong>. Jinja simplifies many things for a
template designer. Loops can be used in a recursive way, filters are
available to format values, loops know about their iteration etc.</li>
<li><strong>Dynamic Syntax</strong>. You don't like the Django block syntax?
You can override the syntax elements on environment initialisation. It's
no problem to use ASP/PHP/Ruby syntax, html comments for blocks etc.</li>
</ul>
<% endblock %>