Python金字塔添加多个变色龙基础模板

2024-04-25 13:25:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用this过程来使用其他模板可以从中派生的基模板。在

如何创建多个基本模板?在


Tags: 模板过程this
1条回答
网友
1楼 · 发布于 2024-04-25 13:25:22

只需同时注册:

from pyramid.renderers import get_renderer

def add_base_template(event):
    base = get_renderer('templates/base.pt').implementation()
    base2 = get_renderer('templates/base2.pt').implementation()
    event.update({'base': base, 'base2': base2})

然后为每个页面选择要在模板中使用的内容:

^{pr2}$
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      metal:use-macro="base2">
    <tal:block metal:fill-slot="content">
        Content on a totally different page.
    </tal:block>

我相信一个模板不一定是整个HTML元素,所以可以将2个宏扩展到同一个最终模板中

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal">
    <body>
        <div metal:use-macro="section1">
            <tal:block metal:fill-slot="content">
                Content for template "section1".
            </tal:block>
        </div>
        <div metal:use-macro="section2">
            <tal:block metal:fill-slot="content">
                Content for template "section2".
            </tal:block>
        </div>
    </body>

相关问题 更多 >

    热门问题