开发者

Genshi Layout Include In Chameleon ZPT

In Genshi, you can do include for layout (which to me is the only way to ens开发者_开发问答ure all the 500 content templates will have the same layout) --

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

Is this possible in Chameleon ZPT? BTW, I've tried Chameleon-genshi a few weeks ago but it was still too buggy for production.

Thanks.


You could try something like this:

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>

Which gives:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Title :: My Website</title>
</head>
<body>
    <div>
    <h2>Title</h2>
</div>

</body>

I just started using Chameleon ZPT so if anyone can point out any flaws in my example I would appreciate it :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜