在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,但它仍然太过繁琐,不适合生产。
谢谢。
发布于 2011-02-15 20:16:33
您可以尝试如下所示:
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,所以如果有人能指出我示例中的任何缺陷,我将不胜感激:)
https://stackoverflow.com/questions/4824556
复制相似问题