2011-07-08 8 views

答えて

3

ちょうどそれらの両方登録:私はテンプレートをする必要はありません信じて

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

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

し、各ページのテンプレートで使用するかを選択しますHTML要素全体であるので、代わりに2つのマクロを同じ最終テンプレートに展開することができます

<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

完璧に動作します!ありがとう! – Sukumar

関連する問題