我可以在另一个变色龙模板中嵌套多个模板对象吗?

时间:2016-01-28 17:16:06

标签: python pyramid template-engine chameleon template-metal

假设我有一个用户对象的变色龙模板文件,其中包含以下内容:

<h2><tal:content="user.name"></h2>
<h4><tal:content="user.occupation"></h4>
<p><tal:content="user.bio"></p>

我是否可以遍历其他模板文件中的用户列表以填充多个内容插槽,如下所示?

<tal:block repeat="user users">
    <div metal:define-slot='user'></div> <!-- ??? -->
</tal:block>

我想如果页面包含要显示大量数据的复杂对象列表,这可能会很有用,但我找不到任何有关它的内容,而且我不知道要给出哪些搜索字词谷歌。

现在我有这样的事情:

<tal:block repeat="user users">
    <h2><tal:content="user.name"</h2>
    <h4><tal:content="user.occupation"></h4>
    <p><tal:content="user.bio"></p>
</tal:block>

这对我来说已经足够了,但我只是想知道我问的是否可能。

1 个答案:

答案 0 :(得分:1)

您正在寻找的是金属宏。一开始他们会让人感到困惑,但是一旦你了解他们的话就会超级强大。

https://chameleon.readthedocs.org/en/latest/reference.html?highlight=metal#metal

HTH

相关问题