2011-07-08 2 views

Répondre

3

les enregistrer juste les deux:

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

Et puis choisir lequel utiliser dans votre modèle pour chaque 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> 

Je crois qu'un modèle ne doit pas être l'élément HTML complet, de sorte que vous pourriez plutôt développer 2 macros dans le même modèle final

<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> 
+0

Fonctionne parfaitement! Merci! – Sukumar

Questions connexes