| 238 | |
| 239 | To reuse common snippets of template code, you can include other files using [http://www.w3.org/TR/xinclude/ XInclude]. |
| 240 | |
| 241 | For this, you need to declare the XInclude namespace (commonly bound to the prefix "xi") and use the `<xi:include>` element where you want the external file to be pulled in: |
| 242 | |
| 243 | {{{ |
| 244 | <html xmlns="http://www.w3.org/1999/xhtml" |
| 245 | xmlns:py="http://markup.edgewall.org/" |
| 246 | xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 247 | <xi:include href="base.html" /> |
| 248 | ... |
| 249 | </html> |
| 250 | }}} |
| 251 | |
| 252 | 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 | |
| 254 | 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 | |
| 256 | {{{ |
| 257 | <xi:include href="base.html"><xi:fallback /></xi:include> |
| 258 | }}} |
| 259 | |
| 260 | See the [http://www.w3.org/TR/xinclude/ XInclude specification] for more about fallback content. Note though that Markup currently only supports a small subset of XInclude. |