Python Pyramid - adding multiple chameleon base templates

I use this procedure to use a basic template from which other templates can be derived.

How to create some basic patterns?

+4
source share
1 answer

Just register both of them:

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}) 

And then choose what to use in the template for each page:

 <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="base"> <tal:block metal:fill-slot="content"> My awesome content. </tal:block> </html> 
 <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> 

I believe that a template should not be an entire HTML element, so you could instead deploy 2 macros into the same final template

 <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> 
+3
source

All Articles