priestc
priestc

Reputation: 35170

render a jinja2 template object in pylons with filters

I'm working on a pylons project that uses jinja2 as its template engine. The project has lots of custom filters added into the template engine.

I have a template object:

>>> t = Template("this is a template {{ var|custom_filter }}!!")
>>> t.render(var="woop woop")

In this example i get TemplateAssertionError: no filter named 'custom_filter' How can I easily render template objects without having to either: load them from files, or manually adding each custom filter each time I want to render a template.

Upvotes: 0

Views: 464

Answers (1)

rxmnnxfpvg
rxmnnxfpvg

Reputation: 30993

You can load the filters into the application environment. Check out this post for Pylons-specific instructions on how to do so:

from yourapp.lib import extensions

config['pylons.app_globals'].jinja2_env = Environment(loader=ChoiceLoader(
            [FileSystemLoader(path) for path in paths['templates']]),
             extensions=[extensions.custom_filter, ...]))

Upvotes: 1

Related Questions