开发者

How do I create a jinja2 filter and use it within pylons?

Am going around the houses trying to find a way to implement a simple filter.

I want to create the equivalent of some Smarty "tags" to make porting easier, notably {mail_to} http://www.smarty.net/manual/en/language.function.mailto.php

I seem to be going around in circles between the jinga2 docs http://jinja.pocoo.org/2/documentation/开发者_C百科extensions#module-jinja2.ext

and the webhelpers http://pylonshq.com/docs/en/0.9.7/modules/templating/

What I'm expecting to write is something like

{% mail_to user=c.user.email encode='hex' %}

Cant figure out how to piece it all together, ie location of lib and how to load for usage.

tia


Write you extension and put it into lib/extensions.py

To load you extension into environment do in config/environment.py:

from MYAPP.lib import extensions

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

# If you extension use some options, you can init it 
config['pylons.app_globals'].jinja2_env.mail_to_smtp_host = 'some_host'

After in yours templates simply call {% mail_to arg1, arg2 %}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜