我四处走动,试图找到一种方法来实现一个简单的过滤器。
我想创建一些智能“标记”的等价物,以简化移植,特别是{mail_to} http://www.smarty.net/manual/en/language.function.mailto.php
我似乎在jinga2文档和http://jinja.pocoo.org/2/documentation/extensions#module-jinja2.ext之间转来转去。
和webhelpers http://pylonshq.com/docs/en/0.9.7/modules/templating/
我希望写的东西是这样的
{% mail_to user=c.user.email encode='hex' %}我想不出如何拼凑在一起,即库的位置和如何加载使用。
提亚
发布于 2010-07-30 23:50:54
编写扩展并将其放入lib/extsions.py中
要将扩展加载到环境中,请在config/ environment ment.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'输入模板后,只需调用{% mail_to arg1,arg2 %}
https://stackoverflow.com/questions/3368597
复制相似问题