]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/template.mdwn
b6083d22580cb62aa999204123b933e96e4a7d9a
[ikiwiki.git] / doc / plugins / template.mdwn
1 [[template id=plugin name=template 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 part of 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 The filled out template will be formatted the same as the rest of the page
42 that contains it, so you can include WikiLinks and all other forms of wiki
43 markup in the template.
44
45 Here's a sample template:
46
47         <span class="infobox">
48         Name: <TMPL_VAR name><br />
49         Age: <TMPL_VAR age><br />
50         <TMPL_IF NAME="color">
51         Favorite color: <TMPL_VAR color><br />
52         <TMPL_ELSE>
53         No favorite color.<br />
54         </TMPL_IF>
55         <TMPL_IF NAME="notes">
56         <hr />
57         <TMPL_VAR notes>
58         </TMPL_IF>
59         </span>