integration.rst
This file
Path
docs/integration.rst
101 lines · 3.5 KiB
Last changed by
Merge branch 'master' of github.com:mitsuhiko/jinja2Armin Ronacherbefore adoption67d015e
History of this fileTake it
The walk stopped after 200 commits: lines older than 41746b9 point at it.
Some more small cleanup for metaclassesArmin Ronacherbefore adoption41746b9
lines 1–8why, one step back1Integration2===========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.78Files to help integration are availableMerge branch 'master' of github.com:mitsuhiko/jinja2Armin Ronacherbefore adoption67d015e
line 9why, one step back9`here. <https://github.com/pallets/jinja/tree/master/ext>`_Some more small cleanup for metaclassesArmin Ronacherbefore adoption41746b9
lines 10–52why, one step back1011.. _babel-integration:1213Babel Integration14-----------------1516Jinja provides support for extracting gettext messages from templates via a17`Babel`_ extractor entry point called `jinja2.ext.babel_extract`. The Babel18support is implemented as part of the :ref:`i18n-extension` extension.1920Gettext messages extracted from both `trans` tags and code expressions.2122To extract gettext messages from templates, the project needs a Jinja2 section23in its Babel extraction method `mapping file`_:2425.. sourcecode:: ini2627 [jinja2: **/templates/**.html]28 encoding = utf-82930The 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:: ini3536 [jinja2: **/templates/**.html]37 encoding = utf-838 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.52Merge branch 'master' of github.com:mitsuhiko/jinja2Armin Ronacherbefore adoption67d015e
line 53why, one step back53.. _mapping file: http://babel.pocoo.org/en/latest/messages.html#extraction-method-mapping-and-configurationSome more small cleanup for metaclassesArmin Ronacherbefore adoption41746b9
lines 54–83why, one step back5455Pylons56------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 configuration62for Jinja2 looks something like that::6364 from jinja2 import Environment, PackageLoader65 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'] = True7879.. _Pylons: http://www.pylonshq.com/8081TextMate82--------83Merge branch 'master' of github.com:mitsuhiko/jinja2Armin Ronacherbefore adoption67d015e
line 84why, one step back84There is a `bundle for TextMate`_ that supports syntax highlighting for Jinja1 and Jinja2 for text basedSome more small cleanup for metaclassesArmin Ronacherbefore adoption41746b9
lines 85–86why, one step back85templates as well as HTML. It also contains a few often used snippets.86Merge branch 'master' of github.com:mitsuhiko/jinja2Armin Ronacherbefore adoption67d015e
lines 87–88why, one step back87.. _bundle for TextMate: https://github.com/mitsuhiko/jinja2-tmbundle88Some more small cleanup for metaclassesArmin Ronacherbefore adoption41746b9
lines 89–99why, one step back89Vim90---9192A syntax plugin for `Vim`_ exists in the Vim-scripts directory as well as the93`ext` folder at the root of the Jinja2 project. `The script94<http://www.vim.org/scripts/script.php?script_id=1856>`_ supports Jinja1 and95Jinja2. Once installed two file types are available `jinja` and `htmljinja`.96The first one for text based templates, the latter for HTML templates.9798Copy the files into your `syntax` folder.99Merge branch 'master' of github.com:mitsuhiko/jinja2Armin Ronacherbefore adoption67d015e
line 100why, one step back100.. _Babel: http://babel.pocoo.org/Some more small cleanup for metaclassesArmin Ronacherbefore adoption41746b9
line 101why, one step back101.. _Vim: http://www.vim.org/