在变色龙中使用基本布局模板 [英] using base layout templates in chameleon
问题描述
在金字塔文档中,这里有一个关于UX的不错的教程:
In the pyramid docs there is a nice tutorial on UX stuff here:
我注意到的一件事是,在本教程中,它们正在代码中显式设置和传递全局布局"(请参见下文).我认为这是不常见且不必要的,因为我一直只使用加载"命令,如此处的文档所示:
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?
教程基础视图类:
class Layouts(object):
@reify
def global_template(self):
renderer = get_renderer("templates/global_layout.pt")
return renderer.implementation().macros['layout']
教程模板文件:
<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>
推荐答案
间接方式(通过视图)可为您提供更大的灵活性.在一个小型项目中,收益并不是那么明显,但是这种方法肯定会在一个较大的项目中获得回报. "load:"正在将您的main_template(用Zope/Plone说话)编码为在此处.使用该视图,它可以来自任何地方,并且可以独立于模板进行更改.
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.
这篇关于在变色龙中使用基本布局模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!