Genshi布局包括Chameleon ZPT

在Genshi中,你可以包括布局(对我而言,这是确保所有500个内容模板具有相同布局的唯一方法) -
"""layout.xml"""
<py:match path="head" once="true">
  <head py:attrs="select('@*')">
    <title>Myapp</title>
  </head>
</py:match>
<py:match path="body" once="true">
  <body py:attrs="select('@*')">
    <div class="main_content">
      <div py:strip="True">${select('*|text()')}</div>
    </div>
  </body>
</py:match>
"""layout.xml"""

"""index.xml"""
<html xmlns:py="http://genshi.edgewall.org/" xmlns:xi="http://
www.w3.org/2001/XInclude">
  <xi:include href="layout.xml" parse="xml"/>
  <head />
  <body>
    <h3>index</h3>
  </body>
</html>
"""index.xml"""

"""rendered index.html"""
<html>
  <head>
    <title>Myapp</title>
  </head>
  <body>
    <div class="main_content">
      <h3>index</h3>
    </div>
  </body>
</html>
"""rendered index.html"""
Chameleon ZPT有可能吗?顺便说一句,几个星期前我曾尝试过Chameleon-genshi,但它仍然因生产过于烦躁。 谢谢。     
已邀请:
你可以尝试这样的事情: layout.pt
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:tal="http://xml.zope.org/namespaces/tal"
  metal:define-macro="layout">
<head>
    <title>${page_title} :: My Website</title>
</head>
<body>
    <div metal:define-slot="main_content">
        Content
    </div>
</body>
</html>
index.pt
<html metal:use-macro="layout.macros['layout']"
  tal:define="page_title 'Title';">
<div metal:fill-slot="main_content">
    <h2 tal:content="page_title">
        Title
    </h2>
</div>
</html>
这使:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Title :: My Website</title>
</head>
<body>
    <div>
    <h2>Title</h2>
</div>

</body>
我刚开始使用Chameleon ZPT,所以如果有人能指出我的例子中的任何缺陷我会很感激:)     

要回复问题请先登录注册