]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/template.mdwn
* Add a destpage parameter to the filter hook.
[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 Some templates are included in the wiki by default; these are listed in the
27 [[templates]] page.
28
29 To create a template, make a page in the wiki named `template/foo`. Note
30 that this is a different location than the directory used for the
31 [[templates|wikitemplates]] used to build the wiki itself, which is not
32 part of the wiki.
33
34 The template uses the syntax used by the [[cpan HTML::Template]] perl
35 module, which allows for some fairly complex things to be done. Consult its
36 documentation for the full syntax, but all you really need to know are a
37 few things:
38
39 * To insert the value of a variable, use `<TMPL_VAR variable>`.
40 * To make a block of text conditional on a variable being set use
41   `<TMPL_IF NAME="variable">text</TMPL_IF>`.
42 * To use one block of text if a variable is set and a second if it's not,
43   use `<TMPL_IF NAME="variable">text<TMPL_ELSE>other text</TMPL_IF>`
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>
60
61 The filled out template will be formatted the same as the rest of the page
62 that contains it, so you can include WikiLinks and all other forms of wiki
63 markup in the template. Note though that such WikiLinks will not show up as
64 backlinks to the page that uses the template.