Edgewall Software

Changes between Version 17 and Version 18 of MarkupTemplates


Ignore:
Timestamp:
Jul 11, 2006, 5:35:11 PM (18 years ago)
Author:
cmlenz
Comment:

Bits of doc for py:def

Legend:

Unmodified
Added
Removed
Modified
  • MarkupTemplates

    v17 v18  
    233233=== `py:def` ===
    234234
     235The `py:def` directive can be used to create ''template functions'', i.e. snippets of template code that have a name and optionally some parameters, and that can be inserted in other places.
     236
     237{{{
     238#!xml
     239<div xmlns:py="http://markup.edgewall.org/">
     240  <p py:def="greeting(name)" class="greeting">
     241    Hello, ${name}!
     242  </p>
     243  ${greeting('world')}
     244  ${greeting('everyone else')}
     245</div>
     246}}}
     247
     248The above would be rendered to:
     249
     250{{{
     251#!xml
     252<div>
     253  <p class="greeting">
     254    Hello, world!
     255  </p>
     256  <p class="greeting">
     257    Hello, everyone else!
     258  </p>
     259</div>
     260}}}
     261
     262This directive can also be used as an element:
     263
     264{{{
     265#!xml
     266<div xmlns:py="http://markup.edgewall.org/">
     267  <py:def function="greeting(name)">
     268    <p class="greeting">Hello, ${name}!</p>
     269  </py:def>
     270</div>
     271}}}
     272
    235273=== `py:match` ===
    236274
     
    252290Include paths are relative to the filename of the template currently being processed. So if the example above was in the file "`myapp/index.html`" (relative to the template search path), the XInclude processor would look for the included file at "`myapp/base.html`". You can also use Unix-style relative paths, for example "`../base.html`" to look in the parent directory.
    253291
     292Any content included this way is inserted into the generated output instead of the `<xi:include>` element. The included template sees the same [wiki:MarkupTemplates#TemplateContext context data]. [wiki:MarkupTemplates#py:match Match templates] and [wiki:MarkupTemplates#py:def template functions] in the included template are also available to the including template after the point it was included.
     293
    254294By default, an error will be raised if an included file is not found. If that's not what you want, you can specify fallback content that should be used if the include fails. For example, to to make the include above fail silently, you'd write:
    255295