using base layout templates in chameleon

1.4k views Asked by At

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

There are 1 answers

1
Roman Susi On BEST ANSWER

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.