pyramid_jinja2
API¶
- pyramid_jinja2.includeme(config)¶
Set up standard configurator registrations. Use via:
config = Configurator() config.include('pyramid_jinja2')
Once this function has been invoked, the
.jinja2
renderer is available for use in Pyramid and these new directives are available as methods of the configurator:add_jinja2_renderer
: Add a new Jinja2 renderer, with a different file extension and/or settings.add_jinja2_search_path
: Add a new location to the search path for the specified renderer.add_jinja2_extension
: Add a list of extensions to the Jinja2 environment used by the specified renderer.get_jinja2_environment
: Return thejinja2.Environment
used by the specified renderer.
- pyramid_jinja2.add_jinja2_renderer(config, name, settings_prefix='jinja2.', package=None)¶
This function is added as a method of a Configurator, and should not be called directly. Instead it should be called like so after
pyramid_jinja2
has been passed toconfig.include
:config.add_jinja2_renderer('.html', settings_prefix='jinja2.')
It will register a new renderer, loaded from settings at the specified
settings_prefix
prefix. This renderer will be active for files using the specified extensionname
.
- pyramid_jinja2.add_jinja2_search_path(config, searchpath, name='.jinja2', prepend=False)¶
This function is added as a method of a Configurator, and should not be called directly. Instead it should be called like so after
pyramid_jinja2
has been passed toconfig.include
:config.add_jinja2_search_path('anotherpackage:templates/')
It will add the directory or asset specification passed as
searchpath
to the current search path of thejinja2.Environment
used by the renderer identified byname
.By default the path is appended to the end of the search path. If
prepend
is set toTrue
then the path will be inserted at the start of the search path.
- pyramid_jinja2.add_jinja2_extension(config, ext, name='.jinja2')¶
This function is added as a method of a Configurator, and should not be called directly. Instead it should be called like so after
pyramid_jinja2
has been passed toconfig.include
:config.add_jinja2_extension(myext)
It will add the Jinja2 extension passed as
ext
to the currentjinja2.Environment
used by the renderer namedname
.
- pyramid_jinja2.get_jinja2_environment(config, name='.jinja2')¶
This function is added as a method of a Configurator, and should not be called directly. Instead it should be called like so after
pyramid_jinja2
has been passed toconfig.include
:config.get_jinja2_environment()
It will return the configured
jinja2.Environment
for the renderer namedname
. The environment is created as an action which is deferred to allow users to override the configuration. In order to get back the configured environment, you must either force a commit viaconfig.commit
or schedule an action which can setup the environment after it has been created:def setup_jinja2_env(): env = config.get_jinja2_environment() # ... config.action(None, setup_jinja2_env, order=999)
- class pyramid_jinja2.Jinja2TemplateRenderer(template_loader)¶
Renderer for a jinja2 template
- class pyramid_jinja2.SmartAssetSpecLoader(searchpath=(), encoding='utf-8', debug=False)¶
A Jinja2 template loader that knows how to handle asset specifications.
- class pyramid_jinja2.i18n.GetTextWrapper(domain)¶
Implements gettext and ngettext functions for
jinja2.Environment.install_gettext_translations()
- gettext(message, mapping=None)¶
Implements jinja.ext.i18n gettext function
- ngettext(singular, plural, n)¶
Implements jinja.ext.i18n ngettext function