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 fileTake 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 back1.. _jinja-extensions:23Extensions4==========5Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 6why, one step back6Jinja supports extensions that can add extra filters, tests, globals or evenMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 7–13why, one step back7extend the parser. The main motivation of extensions is to move often used8code into a reusable class like adding support for internationalization.91011Adding Extensions12-----------------13Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 14why, one step back14Extensions are added to the Jinja environment at creation time. Once theMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 15–16why, one step back15environment is created additional extensions cannot be added. To add an16extension pass a list of extension classes or import paths to theMerge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 17why, one step back17``extensions`` parameter of the :class:`~jinja2.Environment` constructor. The followingMerge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 18why, one step back18example creates a Jinja environment with the i18n extension loaded::Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 19why, one step back19Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 20why, one step back20 jinja_env = Environment(extensions=['jinja2.ext.i18n'])Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 21–27why, one step back212223.. _i18n-extension:2425i18n Extension26--------------27Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 28why, one step back28**Import name:** ``jinja2.ext.i18n``Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 29why, one step back29Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 30–32why, one step back30The i18n extension can be used in combination with `gettext`_ or31`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 back33Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 34–36why, one step back34After enabling, an application has to provide ``gettext`` and35``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 back3738Environment Methods39~~~~~~~~~~~~~~~~~~~4041After enabling the extension, the environment provides the following42additional methods:43Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 44why, one step back44.. method:: jinja2.Environment.install_gettext_translations(translations, newstyle=False)Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 45why, one step back45Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 46–50why, one step back46 Installs a translation globally for the environment. The47 ``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 back51Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
line 52why, one step back52 .. versionchanged:: 2.5 Added new-style gettext support.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 53why, one step back53Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 54why, one step back54.. method:: jinja2.Environment.install_null_translations(newstyle=False)Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 55why, one step back55Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 56–58why, one step back56 Install no-op gettext functions. This is useful if you want to57 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 back59Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
line 60why, one step back60 .. versionchanged:: 2.5 Added new-style gettext support.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 61why, one step back61Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 62why, one step back62.. method:: jinja2.Environment.install_gettext_callables(gettext, ngettext, newstyle=False)Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 63why, one step back63Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 64–67why, one step back64 Install the given ``gettext`` and ``ngettext`` callables into the65 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 back68Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
line 69why, one step back69 If ``newstyle`` is activated, the callables are wrapped to work likeMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 70–71why, one step back70 newstyle callables. See :ref:`newstyle-gettext` for more information.71Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
line 72why, one step back72 .. versionadded:: 2.5 Added new-style gettext support.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 73why, one step back73Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 74why, one step back74.. method:: jinja2.Environment.uninstall_gettext_translations()Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 75why, one step back75Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
line 76why, one step back76 Uninstall the environment's globally installed translation.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 77why, one step back77Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 78why, one step back78.. method:: jinja2.Environment.extract_translations(source)Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 79–84why, one step back7980 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:84Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 85–90why, one step back85 - ``lineno`` is the number of the line on which the string was86 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 back91Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 92–93why, one step back92 If `Babel`_ is installed, see :ref:`babel-integration` to extract93 the strings.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 94why, one step back94Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 95–98why, one step back95For a web application that is available in multiple languages but gives96all 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 back99Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 100–101why, one step back100.. code-block:: python101Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 102why, one step back102 translations = get_gettext_translations()Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 103why, one step back103 env = Environment(extensions=["jinja2.ext.i18n"])Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 104–105why, one step back104 env.install_gettext_translations(translations)105Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 106–107why, one step back106The ``get_gettext_translations`` function would return the translator107for the current configuration, for example by using ``gettext.find``.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 108why, one step back108Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 109–110why, one step back109The usage of the ``i18n`` extension for template designers is covered in110:ref:`the template documentation <i18n-in-templates>`.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 111why, one step back111Merge branch '2.10.x'David Lordbefore adoption9550dc8
line 112why, one step back112.. _gettext: https://docs.python.org/3/library/gettext.htmlMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 113–115why, one step back113.. _Babel: http://babel.pocoo.org/114115Add support for `{% trans trimmed ... %}`Adrian Moennichbefore adoptione605ff1
lines 116–120why, one step back116Whitespace Trimming117~~~~~~~~~~~~~~~~~~~118119.. versionadded:: 2.10120Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 121–123why, one step back121Within ``{% trans %}`` blocks, it can be useful to trim line breaks and122whitespace 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 back124Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 125–126why, one step back125Linebreaks and surrounding whitespace can be automatically trimmed by126enabling the ``ext.i18n.trimmed`` :ref:`policy <ext-i18n-trimmed>`.Add support for `{% trans trimmed ... %}`Adrian Moennichbefore adoptione605ff1
line 127why, one step back127Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 128why, one step back128Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 129–133why, one step back129.. _newstyle-gettext:130131New Style Gettext132~~~~~~~~~~~~~~~~~133Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 134–135why, one step back134.. versionadded:: 2.5135Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 136–137why, one step back136New style gettext calls are less to type, less error prone, and support137autoescaping better.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 138why, one step back138Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 139–143why, one step back139You can use "new style" gettext calls by setting140``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 back144Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 145–147why, one step back145With standard ``gettext`` calls, string formatting is a separate step146done with the ``|format`` filter. This requires duplicating work for147``ngettext`` calls.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 148why, one step back148Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
line 149why, one step back149.. sourcecode:: jinjaMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 150why, one step back150Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 151–155why, one step back151 {{ 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 back156Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 157–158why, one step back157New style ``gettext`` make formatting part of the call, and behind the158scenes enforce more consistency.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 159why, one step back159Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
line 160why, one step back160.. sourcecode:: jinjaMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 161why, one step back161Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 162–164why, one step back162 {{ 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 back165Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
line 166why, one step back166The advantages of newstyle gettext are:Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 167why, one step back167Merge pull request #1084 from pallets/i18n-docsDavid Lordbefore adoption1b3d6ed
lines 168–180why, one step back168- There's no separate formatting step, you don't have to remember to169 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.180Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 181–184why, one step back181182Expression Statement183--------------------184Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 185why, one step back185**Import name:** ``jinja2.ext.do``Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 186why, one step back186Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
line 187why, one step back187The "do" aka expression-statement extension adds a simple ``do`` tag to theMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 188–195why, one step back188template engine that works like a variable expression but ignores the189return value.190191.. _loopcontrols-extension:192193Loop Controls194-------------195Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 196why, one step back196**Import name:** ``jinja2.ext.loopcontrols``Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 197why, one step back197Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
line 198why, one step back198This extension adds support for ``break`` and ``continue`` in loops. AfterMerge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 199why, one step back199enabling, Jinja provides those two keywords which work exactly like inMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 200–206why, one step back200Python.201202.. _with-extension:203204With Statement205--------------206Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 207why, one step back207**Import name:** ``jinja2.ext.with_``Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 208–210why, one step back208209.. versionchanged:: 2.9210Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
line 211why, one step back211 This extension is now built-in and no longer does anything.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 212–217why, one step back212213.. _autoescape-extension:214215Autoescape Extension216--------------------217Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 218why, one step back218**Import name:** ``jinja2.ext.autoescape``Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 219–221why, one step back219220.. versionchanged:: 2.9221Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
lines 222–223why, one step back222 This extension was removed and is now built-in. Enabling the223 extension no longer does anything.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 224–225why, one step back224225Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
lines 226–230why, one step back226.. _debug-extension:227228Debug Extension229---------------230Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 231why, one step back231**Import name:** ``jinja2.ext.debug``Merge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
lines 232–237why, one step back232233Adds 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.236237Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 238–242why, one step back238.. _writing-extensions:239240Writing Extensions241------------------242Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 243why, one step back243.. module:: jinja2.extMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 244why, one step back244Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 245why, one step back245By writing extensions you can add custom tags to Jinja. This is a non-trivialMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 246–250why, one step back246task and usually not needed as the default tags and expressions cover all247common 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 theMerge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 251why, one step back251Jinja template compiler which does not validate the node tree you are passingMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 252–257why, one step back252to it. If the AST is malformed you will get all kinds of compiler or runtime253errors 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.256257Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 258–263why, one step back258Example Extensions259------------------260261Cache262~~~~~263Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 264why, one step back264The following example implements a ``cache`` tag for Jinja by using theMerge branch '2.10.x'David Lordbefore adoption9550dc8
line 265why, one step back265`cachelib`_ library:Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 266why, one step back266Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 267why, one step back267.. literalinclude:: examples/cache_extension.pyMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 268–271why, one step back268 :language: python269270And here is how you use it in an environment::271Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 272why, one step back272 from jinja2 import EnvironmentMerge branch '2.10.x'David Lordbefore adoption9550dc8
line 273why, one step back273 from cachelib import SimpleCacheMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 274–288why, one step back274275 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 %}288Merge branch '2.10.x'David Lordbefore adoption9550dc8
line 289why, one step back289.. _cachelib: https://github.com/pallets/cachelibMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 290why, one step back290Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 291–309why, one step back291292Inline ``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: python308309Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 310why, one step back310Extension APIMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 311why, one step back311-------------Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 312why, one step back312Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 313–315why, one step back313Extension314~~~~~~~~~315Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 316why, one step back316Extensions always have to extend the :class:`jinja2.ext.Extension` class:Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 317–331why, one step back317318.. 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.330331Merge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
lines 332–334why, one step back332Parser333~~~~~~334Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 335–338why, one step back335The parser passed to :meth:`Extension.parse` provides ways to parse336expressions of different types. The following methods may be used by337extensions:338Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 339why, one step back339.. autoclass:: jinja2.parser.ParserMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 340–347why, one step back340 :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 isMerge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
line 348why, one step back348 ``None``.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 349–355why, one step back349350 .. attribute:: name351352 The load name of the template.353354 .. attribute:: stream355Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 356why, one step back356 The current :class:`~jinja2.lexer.TokenStream`Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 357why, one step back357Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 358why, one step back358.. autoclass:: jinja2.lexer.TokenStreamMerge pull request #738 from davidism/test-configDavid Lordbefore adoption05b55d5
line 359why, one step back359 :members: push, look, eos, skip, __next__, next_if, skip_if, expectMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 360–362why, one step back360361 .. attribute:: current362Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 363why, one step back363 The current :class:`~jinja2.lexer.Token`.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 364why, one step back364Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 365why, one step back365.. autoclass:: jinja2.lexer.TokenMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 366–374why, one step back366 :members: test, test_any367368 .. attribute:: lineno369370 The line number of the token371372 .. attribute:: type373374 The type of the token. This string is interned so you may compareMerge pull request #983 from kevin-brown/pr/798David Lordbefore adoption3ea88fe
line 375why, one step back375 it with arbitrary strings using the ``is`` operator.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 376–383why, one step back376377 .. attribute:: value378379 The value of the token.380381There is also a utility function in the lexer module that can count newline382characters in strings:383Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 384why, one step back384.. autofunction:: jinja2.lexer.count_newlinesMerge pull request #1125 from pallets/styleDavid Lordbefore adoption42d4a4e
line 385why, one step back385Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 386–395why, one step back386387AST388~~~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 mayMerge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 396why, one step back396change between Jinja versions but will stay backwards compatible.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 397why, one step back397Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 398why, one step back398For 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 back399Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 400why, one step back400.. module:: jinja2.nodesMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 401why, one step back401Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 402why, one step back402.. jinja:nodes:: jinja2.nodes.NodeMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 403–404why, one step back403404.. autoexception:: Impossible