"nonlocal" keyword. This means that you can now override variables
defined in the outer scope from within a loop.
-- ``foo + bar`` is now a simpler alternative to ``foo|string + bar|string``
+- ``foo ~ bar`` is now a simpler alternative to ``foo|string + bar|string``
- `PackageLoader` can now work without pkg_resources too
-include docs/build/*.html
include Makefile CHANGES LICENSE AUTHORS TODO ez_setup.py
+include docs/build/*.html
+include docs/src/*.txt
recursive-include tests *
If you have numerical indices you have to use the [] syntax:
{{ users[0].username }}
+*new in Jinja 1.2*: You can now use django like attributes for integer
+indices. Thus ``{{ foo.0 }}`` is equivalent to ``{{ foo[0] }}``.
+
+
Loops
=====
``//`` divide the left operand by the right one and return a truncated
integer result: ``{{ 20 // 7 }}`` is ``2``.
*added in Jinja 1.1*
+ ``~`` string concatenate a value with another one. ``{{ foo ~ bar }}``
+ is equivalent to ``{{ foo|string + bar|string }}``. *added in
+ Jinja 1.1*
``*`` multiply the left operand with the right one.
``{{ 2 * 2 }}`` would return ``4``.
``**`` raise the left operand to the power of the right
instead of ``not foo is bar`` and ``not foo in bar``. All other expressions
require a prefix notation: ``not (foo and bar)``.
+
+With Jinja 1.2 onwards it's possible to replace basic if/else blocks with the
+inline `if` / `else` expression. The following two examples evaluate to the
+same:
+
+.. source:: jinja
+
+ {{ "something" if expr else "otherthing" }}
+
+ {% if expr %}something{% else %}otherthing{% endif %}
+
+
Boolean Values
==============
For information regarding the visibility of macros have a look at the
`Scopes and Variable Behavior`_ section.
+
Extended Macro Call
===================
evaluated in an indepdendent environment by calling `rendertemplate`. See the
documentation for this function in the `builtins`_ documentation.
+
Filtering Blocks
================
returns ``"<b>some text</b>"``.
+
Defining Variables
==================
For information regarding the visibility of variables have a look at the
`Scopes and Variable Behavior`_ section.
+
Reserved Keywords
=================
Jinja has some keywords you cannot use a variable names. This limitation
-exists to make look coherent. Syntax highlighters won't mess things up and
-you will don't have unexpected output.
+exists to make templates look coherent. Syntax highlighters won't mess things
+up and you won't have the situation that some names work depending on the
+context.
The following keywords exist and cannot be used as identifiers:
Here some recipies for application developers.
+
Automagic Template Variables
============================
The ``{% extends %}`` tag is the key here. It tells the template engine that
this template "extends" another template. When the template system evaluates
-this template, first it locates the parent.
+this template, first it locates the parent. It must be always the first tag
+in a template but whitespace or a comment is allowed before. This was not
+enforced with Jinja 1.0 and 1.1, it does however raise a syntax error with
+1.2 or later.
The filename of the template depends on the template loader. For example the
``FileSystemLoader`` allows you to access other templates by giving the
two similarly-named ``{% block %}`` tags in a template, that template's
parent wouldn't know which one of the blocks' content to use.
+
How Inheritance Works Internally
================================
However the condition is handled at runtime because it's in a valid block
and defines a new block subtemplates can override.
+
Super Blocks
============
{{ super(2) }}
return the data of the second parent block
+
Block Shortcuts
===============
If you want to play around with the code
----------------------------------------
-1. Install `Subversion`_
-2. ``svn co http://trac.pocoo.org/repos/jinja/trunk jinja``
+1. Install `mercurial`_
+2. ``svn co http://dev.pocoo.org/hg/jinja-main jinja``
3. ``cd jinja``
4. ``ln -s jinja /usr/lib/python2.X/site-packages``
.. _download page: http://jinja.pocoo.org/download.html
.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
-.. _Subversion: http://subversion.tigris.org/
+.. _mercurial: http://www.selenic.com/mercurial/
.. _memcached: http://www.danga.com/memcached/
.. _python-memcached: http://www.tummy.com/Community/software/python-memcached/
+
How Mixin Classes Work
======================
This section covers the behavior of global objects in the Jinja namespace and
also the behavior of their attributes.
+
Functions
=========
This section of the documentation covers the Jinja behavior regarding
variable visibility.
+
Scopes
======
affected by the scoping too. A macro defined inside of a macro is just available
in those two macros (the macro itself and the macro it's defined in).
+
Template Globals
================
it impossible to use conditional expressions for inclusion in non root
templates.
+
Undefined Variables
===================
"""
Uses a memcached server to cache the templates.
- Requires the memcache library from tummy__.
+ Requires the memcache library from `tummy`_ or the cmemcache library
+ from `Gijsbert de Haan`_.
With Jinja 1.2 onwards you can also provide a `client` keyword argument
that takes an already instanciated memcache client or memcache client
like object.
- __ http://www.tummy.com/Community/software/python-memcached/
+ .. _tummy: http://www.tummy.com/Community/software/python-memcached/
+ .. _Gisjsbert de Haan: http://gijsbert.org/cmemcache/
"""
def __init__(self, use_memcache, memcache_time=60 * 60 * 24 * 7,
setup(
- name = 'Jinja',
- version = '1.2',
- url = 'http://jinja.pocoo.org/',
- license = 'BSD',
- author = 'Armin Ronacher',
- author_email = 'armin.ronacher@active-4.com',
- description = 'A small but fast and easy to use stand-alone template '
- 'engine written in pure python.',
+ name='Jinja',
+ version='1.2',
+ url='http://jinja.pocoo.org/',
+ license='BSD',
+ author='Armin Ronacher',
+ author_email='armin.ronacher@active-4.com',
+ description='A small but fast and easy to use stand-alone template '
+ 'engine written in pure python.',
long_description = getdoc(jinja),
# jinja is egg safe. But because we distribute the documentation
# in form of html and txt files it's a better idea to extract the files
- zip_safe = False,
- classifiers = [
+ zip_safe=False,
+ classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Text Processing :: Markup :: HTML'
],
- keywords = ['python.templating.engines'],
- packages = ['jinja', 'jinja.translators'],
- data_files = [
+ keywords=['python.templating.engines'],
+ packages=['jinja', 'jinja.translators'],
+ data_files=[
('docs', list(list_files('docs/build'))),
('docs/txt', list(list_files('docs/src')))
],
[python.templating.engines]
jinja = jinja.plugin:BuffetPlugin
''',
- extras_require = {'plugin': ['setuptools>=0.6a2']},
- features = {
+ extras_require={'plugin': ['setuptools>=0.6a2']},
+ features={
'speedups': Feature(
'optional C-speed enhancements',
standard = True,
]
)
},
- cmdclass = {'build_ext': optional_build_ext}
+ cmdclass={'build_ext': optional_build_ext}
)