using base layout templates in chameleon

怎甘沉沦 提交于 2019-12-12 13:16:40

问题


In the pyramid docs there is a nice tutorial on UX stuff here:

http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/humans/creatingux/step07/index.html

One thing I noticed though is in the tutorial they are setting up and passing around the 'global layout' explicitly in the code (see below). I thought this was unusual and unnecessary because I've always just used the 'load' command as shown in the docs here:

http://chameleon.repoze.org/docs/latest/

Is this just a personal preference issue or are there real advantages to setting up and using the 'global layout' in this way?

Tutorial base view class:

class Layouts(object):
    @reify
    def global_template(self):
        renderer = get_renderer("templates/global_layout.pt")
        return renderer.implementation().macros['layout']

Tutorial template file:

<div metal:use-macro="view.global_template">
    <div metal:fill-slot="content">
        <p>Home page content goes here.</p>
    </div>
</div>

But in my template files I just use:

<div metal:use-macro="load: global_layout.pt">
    <div metal:fill-slot="content">
        <p>Home page content goes here.</p>
    </div>
</div>

回答1:


The indirect way (via view) gives you more flexibility. The benefits are not so obvious in a small project, but this approach surely pays off in a larger one. The "load:" is harcoding your main_template (in Zope/Plone-speak) to be here. With the view, it can come from anywhere and changed independently of your templates.



来源:https://stackoverflow.com/questions/8845435/using-base-layout-templates-in-chameleon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!