syntax.html
This file
Path
syntax.html
61 lines · 1.2 KiB · HTML
Last changed by
[svn] added new jinja trunkArmin Ronacherbefore adoption92f572f
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162Jinja 1.0 Syntax================
<ul>{% for char in my_string|upper|replace(" ", "") %} <li>{{ loop.index }} - {{ char|e }}</li>{% endfor %}</ul>
{{ variable|strip(" ")|escape|replace("a", "b") }}
{% if item == 42 %} ...{% endif %}
{% if item|odd? %} applies the odd? filter which returns true if the item in is odd.{% endif %}
{{ item|e(true) }} -- escape the variable for attributes
<ul>{% for item in seq %} <li>{{ item.current|e }} {% if item.items %}<ul>{% recurse item.items %}</ul>{% endif %} </li>{% endfor %}</ul>
How a Filter Looks Like=======================
def replace(search, repl): def wrapped(env, value): return env.to_unicode(value).replace(search, repl) return wrapped
def escape(attr=False): def wrapped(env, value): return cgi.escape(env.to_unicode(value), attr) return wrapped
def odd(): return lambda env, value: value % 2 == 1odd.__name__ = 'odd?'
@stringfilterdef replace(value, search, repl): return value.replace(search, repl)
def stringfilter(f): def decorator(*args): def wrapped(env, value): return f(env.to_unicode(value), *args) return wrapped return decorator