Skip to content
Myr

integration.rst

This file

Path

docs/integration.rst

106 lines · 3.7 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–3why, one step back
1Integration
2===========3

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

line 4why, one step back
4Jinja provides some code for integration into other tools such as frameworks,

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 5–16why, one step back
5the `Babel`_ library or your favourite editor for fancy code highlighting.
6This is a brief description of whats included.78Files to help integration are available9`here. <https://github.com/pallets/jinja/tree/master/ext>`_1011.. _babel-integration:1213Babel Integration14-----------------1516Jinja provides support for extracting gettext messages from templates via a

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

line 17why, one step back
17`Babel`_ extractor entry point called `jinja2.ext.babel_extract`. The Babel

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 18–21why, one step back
18support is implemented as part of the :ref:`i18n-extension` extension.
1920Gettext messages extracted from both `trans` tags and code expressions.21

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

line 22why, one step back
22To extract gettext messages from templates, the project needs a Jinja section

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 23–26why, one step back
23in its Babel extraction method `mapping file`_:
2425.. sourcecode:: ini26

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

line 27why, one step back
27 [jinja2: **/templates/**.html]

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 28–35why, one step back
28 encoding = utf-8
2930The syntax related options of the :class:`Environment` are also available as31configuration values in the mapping file. For example to tell the extraction32that templates use ``%`` as `line_statement_prefix` you can use this code:3334.. sourcecode:: ini35

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

line 36why, one step back
36 [jinja2: **/templates/**.html]

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 37–61why, one step back
37 encoding = utf-8
38 line_statement_prefix = %3940:ref:`jinja-extensions` may also be defined by passing a comma separated list41of import paths as `extensions` value. The i18n extension is added42automatically.4344.. versionchanged:: 2.74546 Until 2.7 template syntax errors were always ignored. This was done47 since many people are dropping non template html files into the48 templates folder and it would randomly fail. The assumption was that49 testsuites will catch syntax errors in templates anyways. If you don't50 want that behavior you can add ``silent=false`` to the settings and51 exceptions are propagated.5253.. _mapping file: http://babel.pocoo.org/en/latest/messages.html#extraction-method-mapping-and-configuration5455Pylons56------5758With `Pylons`_ 0.9.7 onwards it's incredible easy to integrate Jinja into a59Pylons powered application.6061The template engine is configured in `config/environment.py`. The configuration

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

line 62why, one step back
62for Jinja looks something like that::

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 63why, one step back
63

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

line 64why, one step back
64 from jinja2 import Environment, PackageLoader

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 65–78why, one step back
65 config['pylons.app_globals'].jinja_env = Environment(
66 loader=PackageLoader('yourapplication', 'templates')67 )6869After that you can render Jinja templates by using the `render_jinja` function70from the `pylons.templating` module.7172Additionally it's a good idea to set the Pylons' `c` object into strict mode.73Per default any attribute to not existing attributes on the `c` object return74an empty string and not an undefined object. To change this just use this75snippet and add it into your `config/environment.py`::7677 config['pylons.strict_c'] = True78

Merge branch '2.10.x'David Lordbefore adoption9550dc8

line 79why, one step back
79.. _Pylons: https://pylonshq.com/

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 80–83why, one step back
80
81TextMate82--------83

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

lines 84–85why, one step back
84There is a `bundle for TextMate`_ that supports syntax highlighting for Jinja 1
85and Jinja 2 for text based templates as well as HTML. It also contains a few

Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753

line 86why, one step back
86often used snippets.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 87–92why, one step back
87
88.. _bundle for TextMate: https://github.com/mitsuhiko/jinja2-tmbundle8990Vim91---92

Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753

lines 93–94why, one step back
93A syntax plugin for `Vim`_ is available `from the jinja repository
94<https://github.com/pallets/jinja/blob/master/ext/Vim/jinja.vim>`_. The script

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

line 95why, one step back
95supports Jinja 1 and Jinja 2. Once installed, two file types are available

Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753

lines 96–98why, one step back
96(``jinja`` and ``htmljinja``). The first one is for text-based templates and the
97second is for HTML templates. For HTML documents, the plugin attempts to98automatically detect Jinja syntax inside of existing HTML documents.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

line 99why, one step back
99

Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753

lines 100–102why, one step back
100If you are using a plugin manager like `Pathogen`_, see the `vim-jinja
101<https://github.com/mitsuhiko/vim-jinja>`_ repository for installing in the102``bundle/`` directory.

Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4

lines 103–104why, one step back
103
104.. _Babel: http://babel.pocoo.org/

Merge branch '2.10.x'David Lordbefore adoption9550dc8

line 105why, one step back
105.. _Vim: https://www.vim.org/

Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753

line 106why, one step back
106.. _Pathogen: https://github.com/tpope/vim-pathogen