Skip to content
Myr

extensions.rst

This file

Path

docs/extensions.rst

404 lines · 11.9 KiB

Last changed by

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

History of this file

Take it

The walk stopped after 200 commits: lines older than 793ddd4 point at it.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 1–5why, one step back
1.. _jinja-extensions:
23Extensions4==========5

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 6why, one step back
6Jinja supports extensions that can add extra filters, tests, globals or even

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 7–13why, one step back
7extend the parser. The main motivation of extensions is to move often used
8code into a reusable class like adding support for internationalization.91011Adding Extensions12-----------------13

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 14why, one step back
14Extensions are added to the Jinja environment at creation time. Once the

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 15–16why, one step back
15environment is created additional extensions cannot be added. To add an
16extension pass a list of extension classes or import paths to the

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 17why, one step back
17``extensions`` parameter of the :class:`~jinja2.Environment` constructor. The following

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 18why, one step back
18example creates a Jinja environment with the i18n extension loaded::

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 19why, one step back
19

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 20why, one step back
20 jinja_env = Environment(extensions=['jinja2.ext.i18n'])

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 21–27why, one step back
21
2223.. _i18n-extension:2425i18n Extension26--------------27

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 28why, one step back
28**Import name:** ``jinja2.ext.i18n``

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 29why, one step back
29

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 30–32why, one step back
30The i18n extension can be used in combination with `gettext`_ or
31`Babel`_. When it's enabled, Jinja provides a ``trans`` statement that32marks a block as translatable and calls ``gettext``.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 33why, one step back
33

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 34–36why, one step back
34After enabling, an application has to provide ``gettext`` and
35``ngettext`` functions, either globally or when rendering. A ``_()``36function is added as an alias to the ``gettext`` function.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 37–43why, one step back
37
38Environment Methods39~~~~~~~~~~~~~~~~~~~4041After enabling the extension, the environment provides the following42additional methods:43

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 44why, one step back
44.. method:: jinja2.Environment.install_gettext_translations(translations, newstyle=False)

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 45why, one step back
45

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 46–50why, one step back
46 Installs a translation globally for the environment. The
47 ``translations`` object must implement ``gettext`` and ``ngettext``48 (or ``ugettext`` and ``ungettext`` for Python 2).49 :class:`gettext.NullTranslations`, :class:`gettext.GNUTranslations`,50 and `Babel`_\s ``Translations`` are supported.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 51why, one step back
51

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

line 52why, one step back
52 .. versionchanged:: 2.5 Added new-style gettext support.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 53why, one step back
53

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 54why, one step back
54.. method:: jinja2.Environment.install_null_translations(newstyle=False)

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 55why, one step back
55

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 56–58why, one step back
56 Install no-op gettext functions. This is useful if you want to
57 prepare the application for internationalization but don't want to58 implement the full system yet.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 59why, one step back
59

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

line 60why, one step back
60 .. versionchanged:: 2.5 Added new-style gettext support.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 61why, one step back
61

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 62why, one step back
62.. method:: jinja2.Environment.install_gettext_callables(gettext, ngettext, newstyle=False)

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 63why, one step back
63

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 64–67why, one step back
64 Install the given ``gettext`` and ``ngettext`` callables into the
65 environment. They should behave exactly like66 :func:`gettext.gettext` and :func:`gettext.ngettext` (or67 ``ugettext`` and ``ungettext`` for Python 2).

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 68why, one step back
68

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

line 69why, one step back
69 If ``newstyle`` is activated, the callables are wrapped to work like

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 70–71why, one step back
70 newstyle callables. See :ref:`newstyle-gettext` for more information.
71

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

line 72why, one step back
72 .. versionadded:: 2.5 Added new-style gettext support.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 73why, one step back
73

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 74why, one step back
74.. method:: jinja2.Environment.uninstall_gettext_translations()

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 75why, one step back
75

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

line 76why, one step back
76 Uninstall the environment's globally installed translation.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 77why, one step back
77

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 78why, one step back
78.. method:: jinja2.Environment.extract_translations(source)

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 79–84why, one step back
79
80 Extract localizable strings from the given template node or source.8182 For every string found this function yields a ``(lineno, function,83 message)`` tuple, where:84

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 85–90why, one step back
85 - ``lineno`` is the number of the line on which the string was
86 found.87 - ``function`` is the name of the ``gettext`` function used (if88 the string was extracted from embedded Python code).89 - ``message`` is the string itself (``unicode`` on Python 2), or a90 tuple of strings for functions with multiple arguments.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 91why, one step back
91

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 92–93why, one step back
92 If `Babel`_ is installed, see :ref:`babel-integration` to extract
93 the strings.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 94why, one step back
94

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 95–98why, one step back
95For a web application that is available in multiple languages but gives
96all the users the same language (for example, multilingual forum97software installed for a French community), the translation may be98installed when the environment is created.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 99why, one step back
99

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 100–101why, one step back
100.. code-block:: python
101

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 102why, one step back
102 translations = get_gettext_translations()

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 103why, one step back
103 env = Environment(extensions=["jinja2.ext.i18n"])

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 104–105why, one step back
104 env.install_gettext_translations(translations)
105

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 106–107why, one step back
106The ``get_gettext_translations`` function would return the translator
107for the current configuration, for example by using ``gettext.find``.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 108why, one step back
108

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 109–110why, one step back
109The usage of the ``i18n`` extension for template designers is covered in
110:ref:`the template documentation <i18n-in-templates>`.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 111why, one step back
111

Merge branch '2.10.x'David Lordbefore adoption9550dc8

line 112why, one step back
112.. _gettext: https://docs.python.org/3/library/gettext.html

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 113–115why, one step back
113.. _Babel: http://babel.pocoo.org/
114115

Add support for `{% trans trimmed ... %}`Adrian Moennichbefore adoptione605ff1

lines 116–120why, one step back
116Whitespace Trimming
117~~~~~~~~~~~~~~~~~~~118119.. versionadded:: 2.10120

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 121–123why, one step back
121Within ``{% trans %}`` blocks, it can be useful to trim line breaks and
122whitespace so that the block of text looks like a simple string with123single spaces in the translation file.

Add support for `{% trans trimmed ... %}`Adrian Moennichbefore adoptione605ff1

line 124why, one step back
124

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 125–126why, one step back
125Linebreaks and surrounding whitespace can be automatically trimmed by
126enabling the ``ext.i18n.trimmed`` :ref:`policy <ext-i18n-trimmed>`.

Add support for `{% trans trimmed ... %}`Adrian Moennichbefore adoptione605ff1

line 127why, one step back
127

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 128why, one step back
128

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 129–133why, one step back
129.. _newstyle-gettext:
130131New Style Gettext132~~~~~~~~~~~~~~~~~133

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 134–135why, one step back
134.. versionadded:: 2.5
135

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 136–137why, one step back
136New style gettext calls are less to type, less error prone, and support
137autoescaping better.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 138why, one step back
138

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 139–143why, one step back
139You can use "new style" gettext calls by setting
140``env.newstyle_gettext = True`` or passing ``newstyle=True`` to141``env.install_translations``. They are fully supported by the Babel142extraction tool, but might not work as expected with other extraction143tools.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 144why, one step back
144

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 145–147why, one step back
145With standard ``gettext`` calls, string formatting is a separate step
146done with the ``|format`` filter. This requires duplicating work for147``ngettext`` calls.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 148why, one step back
148

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

line 149why, one step back
149.. sourcecode:: jinja

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 150why, one step back
150

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 151–155why, one step back
151 {{ gettext("Hello, World!") }}
152 {{ gettext("Hello, %(name)s!")|format(name=name) }}153 {{ ngettext(154 "%(num)d apple", "%(num)d apples", apples|count155 )|format(num=apples|count) }}

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 156why, one step back
156

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 157–158why, one step back
157New style ``gettext`` make formatting part of the call, and behind the
158scenes enforce more consistency.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 159why, one step back
159

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

line 160why, one step back
160.. sourcecode:: jinja

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 161why, one step back
161

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 162–164why, one step back
162 {{ gettext("Hello, World!") }}
163 {{ gettext("Hello, %(name)s!", name=name) }}164 {{ ngettext("%(num)d apple", "%(num)d apples", apples|count) }}

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 165why, one step back
165

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

line 166why, one step back
166The advantages of newstyle gettext are:

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 167why, one step back
167

Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed

lines 168–180why, one step back
168- There's no separate formatting step, you don't have to remember to
169 use the ``|format`` filter.170- Only named placeholders are allowed. This solves a common problem171 translators face because positional placeholders can't switch172 positions meaningfully. Named placeholders always carry semantic173 information about what value goes where.174- String formatting is used even if no placeholders are used, which175 makes all strings use a consistent format. Remember to escape any176 raw percent signs as ``%%``, such as ``100%%``.177- The translated string is marked safe, formatting performs escaping178 as needed. Mark a parameter as ``|safe`` if it has already been179 escaped.180

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 181–184why, one step back
181
182Expression Statement183--------------------184

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 185why, one step back
185**Import name:** ``jinja2.ext.do``

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 186why, one step back
186

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

line 187why, one step back
187The "do" aka expression-statement extension adds a simple ``do`` tag to the

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 188–195why, one step back
188template engine that works like a variable expression but ignores the
189return value.190191.. _loopcontrols-extension:192193Loop Controls194-------------195

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 196why, one step back
196**Import name:** ``jinja2.ext.loopcontrols``

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 197why, one step back
197

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

line 198why, one step back
198This extension adds support for ``break`` and ``continue`` in loops. After

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 199why, one step back
199enabling, Jinja provides those two keywords which work exactly like in

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 200–206why, one step back
200Python.
201202.. _with-extension:203204With Statement205--------------206

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 207why, one step back
207**Import name:** ``jinja2.ext.with_``

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 208–210why, one step back
208
209.. versionchanged:: 2.9210

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

line 211why, one step back
211 This extension is now built-in and no longer does anything.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 212–217why, one step back
212
213.. _autoescape-extension:214215Autoescape Extension216--------------------217

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 218why, one step back
218**Import name:** ``jinja2.ext.autoescape``

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 219–221why, one step back
219
220.. versionchanged:: 2.9221

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

lines 222–223why, one step back
222 This extension was removed and is now built-in. Enabling the
223 extension no longer does anything.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 224–225why, one step back
224
225

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

lines 226–230why, one step back
226.. _debug-extension:
227228Debug Extension229---------------230

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 231why, one step back
231**Import name:** ``jinja2.ext.debug``

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

lines 232–237why, one step back
232
233Adds a ``{% debug %}`` tag to dump the current context as well as the234available filters and tests. This is useful to see what's available to235use in the template without setting up a debugger.236237

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 238–242why, one step back
238.. _writing-extensions:
239240Writing Extensions241------------------242

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 243why, one step back
243.. module:: jinja2.ext

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 244why, one step back
244

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 245why, one step back
245By writing extensions you can add custom tags to Jinja. This is a non-trivial

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 246–250why, one step back
246task and usually not needed as the default tags and expressions cover all
247common use cases. The i18n extension is a good example of why extensions are248useful. Another one would be fragment caching.249250When writing extensions you have to keep in mind that you are working with the

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 251why, one step back
251Jinja template compiler which does not validate the node tree you are passing

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 252–257why, one step back
252to it. If the AST is malformed you will get all kinds of compiler or runtime
253errors that are horrible to debug. Always make sure you are using the nodes254you create correctly. The API documentation below shows which nodes exist and255how to use them.256257

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 258–263why, one step back
258Example Extensions
259------------------260261Cache262~~~~~263

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 264why, one step back
264The following example implements a ``cache`` tag for Jinja by using the

Merge branch '2.10.x'David Lordbefore adoption9550dc8

line 265why, one step back
265`cachelib`_ library:

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 266why, one step back
266

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 267why, one step back
267.. literalinclude:: examples/cache_extension.py

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 268–271why, one step back
268 :language: python
269270And here is how you use it in an environment::271

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 272why, one step back
272 from jinja2 import Environment

Merge branch '2.10.x'David Lordbefore adoption9550dc8

line 273why, one step back
273 from cachelib import SimpleCache

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 274–288why, one step back
274
275 env = Environment(extensions=[FragmentCacheExtension])276 env.fragment_cache = SimpleCache()277278Inside the template it's then possible to mark blocks as cacheable. The279following example caches a sidebar for 300 seconds:280281.. sourcecode:: html+jinja282283 {% cache 'sidebar', 300 %}284 <div class="sidebar">285 ...286 </div>287 {% endcache %}288

Merge branch '2.10.x'David Lordbefore adoption9550dc8

line 289why, one step back
289.. _cachelib: https://github.com/pallets/cachelib

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 290why, one step back
290

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 291–309why, one step back
291
292Inline ``gettext``293~~~~~~~~~~~~~~~~~~294295The following example demonstrates using :meth:`Extension.filter_stream`296to parse calls to the ``_()`` gettext function inline with static data297without needing Jinja blocks.298299.. code-block:: html300301 <h1>_(Welcome)</h1>302 <p>_(This is a paragraph)</p>303304It requires the i18n extension to be loaded and configured.305306.. literalinclude:: examples/inline_gettext_extension.py307 :language: python308309

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 310why, one step back
310Extension API

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 311why, one step back
311-------------

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 312why, one step back
312

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 313–315why, one step back
313Extension
314~~~~~~~~~315

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 316why, one step back
316Extensions always have to extend the :class:`jinja2.ext.Extension` class:

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 317–331why, one step back
317
318.. autoclass:: Extension319 :members: preprocess, filter_stream, parse, attr, call_method320321 .. attribute:: identifier322323 The identifier of the extension. This is always the true import name324 of the extension class and must not be changed.325326 .. attribute:: tags327328 If the extension implements custom tags this is a set of tag names329 the extension is listening for.330331

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

lines 332–334why, one step back
332Parser
333~~~~~~334

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 335–338why, one step back
335The parser passed to :meth:`Extension.parse` provides ways to parse
336expressions of different types. The following methods may be used by337extensions:338

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 339why, one step back
339.. autoclass:: jinja2.parser.Parser

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 340–347why, one step back
340 :members: parse_expression, parse_tuple, parse_assign_target,
341 parse_statements, free_identifier, fail342343 .. attribute:: filename344345 The filename of the template the parser processes. This is **not**346 the load name of the template. For the load name see :attr:`name`.347 For templates that were not loaded form the file system this is

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

line 348why, one step back
348 ``None``.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 349–355why, one step back
349
350 .. attribute:: name351352 The load name of the template.353354 .. attribute:: stream355

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 356why, one step back
356 The current :class:`~jinja2.lexer.TokenStream`

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 357why, one step back
357

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 358why, one step back
358.. autoclass:: jinja2.lexer.TokenStream

Merge pull request #738 from davidism/test-configDavid Lordbefore adoption05b55d5

line 359why, one step back
359 :members: push, look, eos, skip, __next__, next_if, skip_if, expect

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 360–362why, one step back
360
361 .. attribute:: current362

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 363why, one step back
363 The current :class:`~jinja2.lexer.Token`.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 364why, one step back
364

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 365why, one step back
365.. autoclass:: jinja2.lexer.Token

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 366–374why, one step back
366 :members: test, test_any
367368 .. attribute:: lineno369370 The line number of the token371372 .. attribute:: type373374 The type of the token. This string is interned so you may compare

Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe

line 375why, one step back
375 it with arbitrary strings using the ``is`` operator.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 376–383why, one step back
376
377 .. attribute:: value378379 The value of the token.380381There is also a utility function in the lexer module that can count newline382characters in strings:383

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 384why, one step back
384.. autofunction:: jinja2.lexer.count_newlines

Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e

line 385why, one step back
385

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 386–395why, one step back
386
387AST388~~~389390The AST (Abstract Syntax Tree) is used to represent a template after parsing.391It's build of nodes that the compiler then converts into executable Python392code objects. Extensions that provide custom statements can return nodes to393execute custom Python code.394395The list below describes all nodes that are currently available. The AST may

Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205

line 396why, one step back
396change between Jinja versions but will stay backwards compatible.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 397why, one step back
397

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 398why, one step back
398For more information have a look at the repr of :meth:`jinja2.Environment.parse`.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 399why, one step back
399

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 400why, one step back
400.. module:: jinja2.nodes

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 401why, one step back
401

Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7

line 402why, one step back
402.. jinja:nodes:: jinja2.nodes.Node

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 403–404why, one step back
403
404.. autoexception:: Impossible