原始 Mako 模板包含在 Pylons 的另一个模板中
我试图包含一个原始 Mako 模板,使其出现在带有 Pylons 的文本区域中。
在 Pylons 中,我知道我可以将一个 Mako 模板包含在另一个模板中,如下所示:
<html>
<body>
Here is some HTML. Now, I want to include a template.
<%include file="${c.a_mako_template}" />
</body>
</html>
有没有一种方法可以让我做同样的事情,但让模板显示为原始标记而不是通过 Mako 渲染器?我正在想象这样的事情:
<%include file="${c.a_mako_template}" render="false" />
如果这种事情不可能,那么编写一个 Pylons 控制器在稍后阶段进行包含操作的最佳途径是什么呢?
我可以以某种方式包装文件以包含在 <%text> 中吗?动态标记,也许使用 <% def>?
I'm trying to include a raw Mako template to make it appear in a textarea with Pylons.
In Pylons, I know I can include one Mako template in another like this:
<html>
<body>
Here is some HTML. Now, I want to include a template.
<%include file="${c.a_mako_template}" />
</body>
</html>
Is there a way that I can do the same thing, but have the template appear as raw markup rather than passing through Mako renderer? I'm imagining something like:
<%include file="${c.a_mako_template}" render="false" />
If that sort of thing is impossible, is the best route to write a Pylons controller that does the inclusion at a later stage?
Could I somehow wrap the file to be included in <%text> tags on the fly, perhaps using <% def>?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经想出了一种可行的解决方案。它仍然有一点粗糙,但它确实有效。
第一部分只是模板中嵌入的一段 Python 代码。它打开文件并提取文本,从而绕过 Mako。
粗略的部分是硬编码路径。我必须将其作为 c.path 或类似的东西传递。
I've figured out a sort of workable solution. It still has one rough bit, but it works.
The first part is just a chunk of Python embedded in the template. It opens the file and extracts the text, thereby bypassing Mako.
The rough bit is the hardcoded path. I'll have to pass that as c.path, or something like that.