]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/template.mdwn
cleanup
[ikiwiki.git] / doc / plugins / template.mdwn
1 [[template id=plugin name=template included=1 author="[[Joey]]"]]
2 [[tag type/format]]
3
4 With this plugin, you can set up templates, and cause them to be filled out
5 and inserted into pages in the wiki. Using a template works like this:
6
7         \[[template id=foo name="Charley" color="red" age=11]]
8
9 This fills out the template `templates/foo`, filling in the `color` and `age`
10 fields on it with the specified values, and inserts the result into the page.
11
12 (Note that if the template doesn't exist, the page will provide a link that
13 can be used to create it.)
14
15 A value can include any markup that would be allowed in the wiki page
16 outside the template. Triple-quoting the value even allows quotes to be
17 included in it. Combined with multi-line quoted values, this allows for
18 large chunks of marked up text to be embedded into a template:
19
20         \[[template id=foo name="Sally" color="green" age=8 notes="""
21         * \[[Charley]]'s sister.
22         * "I want to be an astronaut when I grow up."
23         * Really 8 and a half.
24         """]]
25
26 To create a template, make a page in the wiki named `template/foo`. Note
27 that this is a different location than the directory used for the
28 [[templates]] used to build the wiki itself, which is not inside the wiki.
29
30 The template uses the syntax used by the HTML::Template perl module, which
31 allows for some fairly complex things to be done. Consult its documentation
32 for the full syntax, but all you really need to know are a few things:
33
34 * To insert the value of a variable, use `<TMPL_VAR variable>`.
35 * To make a block of text conditional on a variable being set use
36   `<TMPL_IF NAME="variable">text</TMPL_IF>`.
37 * To use one block of text if a variable is set and a second if it's not,
38   use `<TMPL_IF NAME="variable">text<TMPL_ELSE>other text</TMPL_IF>`
39
40 Here's a sample template:
41
42         <span class="infobox">
43         Name: <TMPL_VAR name><br />
44         Age: <TMPL_VAR age><br />
45         <TMPL_IF NAME="color">
46         Favorite color: <TMPL_VAR color><br />
47         <TMPL_ELSE>
48         No favorite color.<br />
49         </TMPL_IF>
50         <TMPL_IF NAME="notes">
51         <hr />
52         <TMPL_VAR notes>
53         </TMPL_IF>
54         </span>