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
[svn] added new jinja trunkArmin Ronacherbefore adoption92f572f
lines 1–611Jinja 1.0 Syntax2================34<ul>5{% for char in my_string|upper|replace(" ", "") %}6 <li>{{ loop.index }} - {{ char|e }}</li>7{% endfor %}8</ul>910{{ variable|strip(" ")|escape|replace("a", "b") }}1112{% if item == 42 %}13 ...14{% endif %}1516{% if item|odd? %}17 applies the odd? filter which returns true if the18 item in is odd.19{% endif %}2021{{ item|e(true) }} -- escape the variable for attributes2223<ul>24{% for item in seq %}25 <li>{{ item.current|e }}26 {% if item.items %}<ul>{% recurse item.items %}</ul>{% endif %}27 </li>28{% endfor %}29</ul>3031How a Filter Looks Like32=======================3334def replace(search, repl):35 def wrapped(env, value):36 return env.to_unicode(value).replace(search, repl)37 return wrapped383940def escape(attr=False):41 def wrapped(env, value):42 return cgi.escape(env.to_unicode(value), attr)43 return wrapped444546def odd():47 return lambda env, value: value % 2 == 148odd.__name__ = 'odd?'495051@stringfilter52def replace(value, search, repl):53 return value.replace(search, repl)545556def stringfilter(f):57 def decorator(*args):58 def wrapped(env, value):59 return f(env.to_unicode(value), *args)60 return wrapped61 return decorator