基本
Documentation/xml-templates.html – Genshi
As a shorthand, if the value of the py:strip attribute is empty, that has the same effect as using a truth value (i.e. the element is stripped).
py:strip="True" は py:strip="" に省略可
複数ディレクティブがある場合の処理順
http://genshi.edgewall.org/wiki/Documentation/xml-templates.html#processing-order
- py:def
- py:match
- py:when
- py:otherwise
- py:for
- py:if
- py:choose
- py:with
- py:replace
- py:content
- py:attrs
- py:strip
for → if
テンプレート中でpythonコードを使う
Documentation/templates.html – Genshi
Templates also support full Python code blocks, using the processing instruction in XML templates:
<div> <?python from genshi.builder import tag def greeting(name): return tag.b('Hello, %s!' % name) ?> ${greeting('world')} </div>
マクロ
Documentation/xml-templates.html – Genshi
<div> <p py:def="greeting(name)" class="greeting"> Hello, ${name}! </p> ${greeting('world')} ${greeting('everyone else')} </div>
<div> <p class="greeting"> Hello, world! </p> <p class="greeting"> Hello, everyone else! </p> </div>
include を使わずパーツ化。部品