Changes between Version 17 and Version 18 of MarkupTemplates
- Timestamp:
- Jul 11, 2006, 5:35:11 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MarkupTemplates
v17 v18 233 233 === `py:def` === 234 234 235 The `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 248 The 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 262 This 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 235 273 === `py:match` === 236 274 … … 252 290 Include 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. 253 291 292 Any 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 254 294 By 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: 255 295