Skip to content
Myr

integration.rst

This file

Path

docs/integration.rst

88 lines · 2.9 KiB

Last changed by

some small documentation fixesArmin Ronacherbefore adoption2b22874

History of this file

Take it

some documentation updatesArmin Ronacherbefore adoptioned98cac

lines 1–23why, one step back
1Integration
2===========34Jinja2 provides some code for integration into other tools such as frameworks,5the `Babel`_ library or your favourite editor for fancy code highlighting.6This is a brief description of whats included.78.. _babel-integration:910Babel Integration11-----------------1213Jinja provides support for extracting gettext messages from templates via a14`Babel`_ extractor entry point called `jinja2.ext.babel_extract`. The Babel15support is implemented as part of the :ref:`i18n-extension` extension.1617Gettext messages extracted from both `trans` tags and code expressions.1819To extract gettext messages from templates, the project needs a Jinja2 section20in its Babel extraction method `mapping file`_:2122.. sourcecode:: ini23

some small documentation fixesArmin Ronacherbefore adoption2b22874

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

some documentation updatesArmin Ronacherbefore adoptioned98cac

lines 25–32why, one step back
25 encoding = utf-8
2627The syntax related options of the :class:`Environment` are also available as28configuration values in the mapping file. For example to tell the extraction29that templates use ``%`` as `line_statement_prefix` you can use this code:3031.. sourcecode:: ini32

some small documentation fixesArmin Ronacherbefore adoption2b22874

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

some documentation updatesArmin Ronacherbefore adoptioned98cac

lines 34–42why, one step back
34 encoding = utf-8
35 line_statement_prefix = %3637:ref:`jinja-extensions` may also be defined by passing a comma separated list38of import paths as `extensions` value. The i18n extension is added39automatically.4041.. _mapping file: http://babel.edgewall.org/wiki/Documentation/messages.html#extraction-method-mapping-and-configuration42

removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826

line 43why, one step back
43Pylons

some documentation updatesArmin Ronacherbefore adoptioned98cac

lines 44–45why, one step back
44------
45

removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826

lines 46–47why, one step back
46With `Pylons`_ 0.9.7 onwards it's incredible easy to integrate Jinja into a
47Pylons powered application.

some documentation updatesArmin Ronacherbefore adoptioned98cac

line 48why, one step back
48

removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826

lines 49–50why, one step back
49The template engine is configured in `config/environment.py`. The configuration
50for Jinja2 looks something like that::

some documentation updatesArmin Ronacherbefore adoptioned98cac

line 51why, one step back
51

removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826

lines 52–55why, one step back
52 from jinja2 import Environment, PackageLoader
53 config['pylons.app_globals'].jinja_env = Environment(54 loader=PackageLoader('yourapplication', 'templates')55 )

some documentation updatesArmin Ronacherbefore adoptioned98cac

line 56why, one step back
56

removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826

lines 57–58why, one step back
57After that you can render Jinja templates by using the `render_jinja` function
58from the `pylons.templating` module.

some documentation updatesArmin Ronacherbefore adoptioned98cac

line 59why, one step back
59

removed wsgi and django from the integration page, wsgi is not interesting and there is no django support module currently. pylons is now documented.Armin Ronacherbefore adoptionba80826

lines 60–67why, one step back
60Additionally it's a good idea to set the Pylons' `c` object into strict mode.
61Per default any attribute to not existing attributes on the `c` object return62an empty string and not an undefined object. To change this just use this63snippet and add it into your `config/environment.py`::6465 config['pylons.strict_c'] = True6667.. _Pylons: http://www.pylonshq.com/

some documentation updatesArmin Ronacherbefore adoptioned98cac

lines 68–71why, one step back
68
69TextMate70--------71

added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3

lines 72–74why, one step back
72Inside the `ext` folder of Jinja2 there is a bundle for TextMate that supports
73syntax highlighting for Jinja1 and Jinja2 for text based templates as well as74HTML. It also contains a few often used snippets.

some documentation updatesArmin Ronacherbefore adoptioned98cac

lines 75–78why, one step back
75
76Vim77---78

added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3

lines 79–83why, one step back
79A syntax plugin for `Vim`_ exists in the Vim-scripts directory as well as the
80ext folder of Jinja2. `The script <http://www.vim.org/scripts/script.php?script_id=1856>`_81supports Jinja1 and Jinja2. Once installed two file types are available `jinja`82and `htmljinja`. The first one for text based templates, the latter for HTML83templates.

some documentation updatesArmin Ronacherbefore adoptioned98cac

line 84why, one step back
84

added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3

lines 85–86why, one step back
85Copy the files into your `syntax` folder.
86

some documentation updatesArmin Ronacherbefore adoptioned98cac

line 87why, one step back
87.. _Babel: http://babel.edgewall.org/

added TextMate bundle and vim syntax filesArmin Ronacherbefore adoptiondecf7e3

line 88why, one step back
88.. _Vim: http://www.vim.org/