genshi

基本

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

  1. py:def
  2. py:match
  3. py:when
  4. py:otherwise
  5. py:for
  6. py:if
  7. py:choose
  8. py:with
  9. py:replace
  10. py:content
  11. py:attrs
  12. 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 を使わずパーツ化。部品