]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/template.mdwn
more
[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 [[cpan HTML::Template]] perl
31 module, which allows for some fairly complex things to be done. Consult its
32 documentation for the full syntax, but all you really need to know are a
33 few things:
34
35 * To insert the value of a variable, use `<TMPL_VAR variable>`.
36 * To make a block of text conditional on a variable being set use
37   `<TMPL_IF NAME="variable">text</TMPL_IF>`.
38 * To use one block of text if a variable is set and a second if it's not,
39   use `<TMPL_IF NAME="variable">text<TMPL_ELSE>other text</TMPL_IF>`
40
41 Here's a sample template:
42
43         <span class="infobox">
44         Name: <TMPL_VAR name><br />
45         Age: <TMPL_VAR age><br />
46         <TMPL_IF NAME="color">
47         Favorite color: <TMPL_VAR color><br />
48         <TMPL_ELSE>
49         No favorite color.<br />
50         </TMPL_IF>
51         <TMPL_IF NAME="notes">
52         <hr />
53         <TMPL_VAR notes>
54         </TMPL_IF>
55         </span>