如何扩展jinja2内置标签?
我试图覆盖 jinja2 中 raw/endraw 块标记的默认实现。我熟悉如何编写自定义标签扩展,但在这种情况下,我的扩展不会触发(原始标签的默认实现仍在调用)。 这还可以吗?如果没有,有人可以指出我在源代码中实现原始标签的位置,以便我可以对其进行修补以满足我的需求。
谢谢。
I am trying to override the default implementation of the raw/endraw block tag in jinja2. I am familiar with how to write custom tag extensions, but in this case my extension is not firing (the default implementation of the raw tag is still being called).
Can this even be done? If not, can someone point me to where in the source the raw tag is implemented so I can patch it to fit my needs.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来不支持覆盖 raw/endraw 标签。
处理 raw/endraw 标签的代码是 直接在词法分析器中,以及处理 是硬编码的。
所以你可能必须修补代码。幸运的是,代码托管在 github 上,因此您可以轻松拥有自己的 jinja2 浅分支,但仍能跟上主发行版的未来改进。
It looks like overriding the raw/endraw tags is not supported.
The code for dealing with the raw/endraw tags is directly in the lexer, and the handling is hard coded.
So you would probably have to patch the code. Luckily, the code is hosted on github, so it would be easy to have your own shallow fork of jinja2, but still keep up to date with future improvements from the main distribution.