]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/template.mdwn
web commit by JordaPolo: Reply to comments; fix my name.
[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 If a value is triple-quoted, it can include any markup that would be
13 allowed in the wiki page outside the template. Combined with multi-line
14 quoted values, this allows for large chunks of marked up text to be
15 embedded into a template:
16
17         \[[template id=foo name="Sally" color="green" age=8 notes="""
18         * \[[Charley]]'s sister.
19         * Really 8 and a half.
20         * Wants to be an astronaut when she grows up.
21         """]]
22
23 To create a template, make a page in the wiki named `template/foo`. Note
24 that this is a different location than the directory used for the
25 [[templates]] used to build the wiki itself, which is not inside the wiki.
26
27 The template uses the syntax used by the HTML::Template perl module, which
28 allows for some fairly complex things to be done. Consult its documentation
29 for the full syntax, but all you really need to know are a few things:
30
31 * To insert the value of a variable, use `<TMPL_VAR variable>`.
32 * To make a block of text conditional on a variable being set use
33   `<TMPL_IF NAME="variable">text</TMPL_IF>`.
34
35 Here's a sample template:
36
37         <span class="infobox">
38         Name: <TMPL_VAR name><br />
39         Age: <TMPL_VAR age><br />
40         <TMPL_IF NAME="color">
41         Favorite color: <TMPL_VAR color><br />
42         <TMPL_ELSE>
43         No favorite color.<br />
44         </TMPL_IF>
45         <TMPL_IF NAME="notes">
46         <hr />
47         <TMPL_VAR notes>
48         </TMPL_IF>
49         </span>