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 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–3why, one step back1Integration2===========3Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 4why, one step back4Jinja provides some code for integration into other tools such as frameworks,Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 5–16why, one step back5the `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 aMerge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 17why, one step back17`Babel`_ extractor entry point called `jinja2.ext.babel_extract`. The BabelMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 18–21why, one step back18support is implemented as part of the :ref:`i18n-extension` extension.1920Gettext messages extracted from both `trans` tags and code expressions.21Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 22why, one step back22To extract gettext messages from templates, the project needs a Jinja sectionMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 23–26why, one step back23in its Babel extraction method `mapping file`_:2425.. sourcecode:: ini26Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 27why, one step back27 [jinja2: **/templates/**.html]Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 28–35why, one step back28 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:: ini35Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 36why, one step back36 [jinja2: **/templates/**.html]Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 37–61why, one step back37 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.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 configurationMerge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 62why, one step back62for Jinja looks something like that::Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
line 63why, one step back63Merge pull request #1133 from pallets/revert-renameDavid Lordbefore adoption15337f7
line 64why, one step back64 from jinja2 import Environment, PackageLoaderMerge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 65–78why, one step back65 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'] = True78Merge branch '2.10.x'David Lordbefore adoption9550dc8
line 79why, one step back79.. _Pylons: https://pylonshq.com/Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 80–83why, one step back8081TextMate82--------83Merge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
lines 84–85why, one step back84There is a `bundle for TextMate`_ that supports syntax highlighting for Jinja 185and Jinja 2 for text based templates as well as HTML. It also contains a fewMerge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753
line 86why, one step back86often used snippets.Merge branch '2.9-maintenance'Armin Ronacherbefore adoption793ddd4
lines 87–92why, one step back8788.. _bundle for TextMate: https://github.com/mitsuhiko/jinja2-tmbundle8990Vim91---92Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753
lines 93–94why, one step back93A syntax plugin for `Vim`_ is available `from the jinja repository94<https://github.com/pallets/jinja/blob/master/ext/Vim/jinja.vim>`_. The scriptMerge pull request #1087 from pallets/jinja-nameDavid Lordbefore adoption1af1205
line 95why, one step back95supports Jinja 1 and Jinja 2. Once installed, two file types are availableMerge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753
lines 96–98why, one step back96(``jinja`` and ``htmljinja``). The first one is for text-based templates and the97second 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 back99Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753
lines 100–102why, one step back100If you are using a plugin manager like `Pathogen`_, see the `vim-jinja101<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 back103104.. _Babel: http://babel.pocoo.org/Merge branch '2.10.x'David Lordbefore adoption9550dc8
line 105why, one step back105.. _Vim: https://www.vim.org/Merge pull request #869 from jwflory/docs/vim-syntaxDavid Lordbefore adoption0273753
line 106why, one step back106.. _Pathogen: https://github.com/tpope/vim-pathogen