OS : Linux
PHP Version : 7.4.33
Software : Apache/2.4.6 (CentOS) PHP/7.4.33
Information System : Linux apprendre2 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
Disable Function :
Jinja2 provides some code for integration into other tools such as frameworks,
the Babel library or your favourite editor for fancy code highlighting.
This is a brief description of whats included. Files to help integration are available
here. Jinja provides support for extracting gettext messages from templates via a
Babel extractor entry point called jinja2.ext.babel_extract. The Babel
support is implemented as part of the i18n Extension extension. Gettext messages extracted from both trans tags and code expressions. To extract gettext messages from templates, the project needs a Jinja2 section
in its Babel extraction method mapping file: The syntax related options of the Environment are also available as
configuration values in the mapping file. For example to tell the extraction
that templates use % as line_statement_prefix you can use this code: Extensions may also be defined by passing a comma separated list
of import paths as extensions value. The i18n extension is added
automatically.
Changed in version 2.7. With Pylons 0.9.7 onwards it’s incredible easy to integrate Jinja into a
Pylons powered application. The template engine is configured in config/environment.py. The configuration
for Jinja2 looks something like that: After that you can render Jinja templates by using the render_jinja function
from the pylons.templating module. Additionally it’s a good idea to set the Pylons’ c object into strict mode.
Per default any attribute to not existing attributes on the c object return
an empty string and not an undefined object. To change this just use this
snippet and add it into your config/environment.py: Inside the ext folder at the root of the Jinja2 project there is a bundle for
TextMate that supports syntax highlighting for Jinja1 and Jinja2 for text based
templates as well as HTML. It also contains a few often used snippets. A syntax plugin for Vim exists in the Vim-scripts directory as well as the
ext folder at the root of the Jinja2 project. The script supports Jinja1 and
Jinja2. Once installed two file types are available jinja and htmljinja.
The first one for text based templates, the latter for HTML templates. Copy the files into your syntax folder.Integration¶
Babel Integration¶
[jinja2: **/templates/**.html]
encoding = utf-8
[jinja2: **/templates/**.html]
encoding = utf-8
line_statement_prefix = %
Pylons¶
from jinja2 import Environment, PackageLoader
config['pylons.app_globals'].jinja_env = Environment(
loader=PackageLoader('yourapplication', 'templates')
)
config['pylons.strict_c'] = True
TextMate¶
Vim¶