]> sipb.mit.edu Git - ikiwiki.git/blob - doc/templates.mdwn
* Setting NOTAINT=1 had no effect when building ikiwiki itself, fix this.
[ikiwiki.git] / doc / templates.mdwn
1 [[!if test="enabled(template)"
2 then="This wiki has templates **enabled**."
3 else="This wiki has templates **disabled**."
4 ]]
5
6 Templates are files that can be filled out and inserted into pages in the
7 wiki.
8
9 [[!if test="enabled(template) and enabled(inline)" then="""
10
11 ## Available templates
12
13 These templates are available for inclusion onto other pages in this
14 wiki:
15
16 [[!inline pages="templates/* and !*/discussion" feeds=no archive=yes
17 sort=title template=titlepage]]
18 """]]
19
20 ## Using a template
21
22 Using a template works like this:
23
24         \[[!template id=note text="""Here is the text to insert into my note."""]]
25
26 This fills out the [[note]] template, filling in the `text` field with
27 the specified value, and inserts the result into the page.
28
29 Generally, a value can include any markup that would be allowed in the wiki
30 page outside the template. Triple-quoting the value even allows quotes to
31 be included in it. Combined with multi-line quoted values, this allows for
32 large chunks of marked up text to be embedded into a template:
33
34         \[[!template id=foo name="Sally" color="green" age=8 notes="""
35         * \[[Charley]]'s sister.
36         * "I want to be an astronaut when I grow up."
37         * Really 8 and a half.
38         """]]
39
40 ## Creating a template
41
42 To create a template, simply add a template directive to a page, and page will
43 provide a link that can be used to create the template. The template is a
44 regular wiki page, located in the `templates/` directory.
45
46 The template uses the syntax used by the [[!cpan HTML::Template]] perl
47 module, which allows for some fairly complex things to be done. Consult its
48 documentation for the full syntax, but all you really need to know are a
49 few things:
50
51 * To insert the value of a variable, use `<TMPL_VAR variable>`. Wiki markup
52   in the value will first be converted to html.
53 * To insert the raw value of a variable, with wiki markup not yet converted
54   to html, use `<TMPL_VAR raw_variable>`.
55 * To make a block of text conditional on a variable being set use
56   `<TMPL_IF NAME="variable">text</TMPL_IF>`.
57 * To use one block of text if a variable is set and a second if it's not,
58   use `<TMPL_IF NAME="variable">text<TMPL_ELSE>other text</TMPL_IF>`
59
60 Here's a sample template:
61
62         <span class="infobox">
63         Name: [[<TMPL_VAR raw_name>]]<br />
64         Age: <TMPL_VAR age><br />
65         <TMPL_IF NAME="color">
66         Favorite color: <TMPL_VAR color><br />
67         <TMPL_ELSE>
68         No favorite color.<br />
69         </TMPL_IF>
70         <TMPL_IF NAME="notes">
71         <hr />
72         <TMPL_VAR notes>
73         </TMPL_IF>
74         </span>
75
76 The filled out template will be formatted the same as the rest of the page
77 that contains it, so you can include WikiLinks and all other forms of wiki
78 markup in the template. Note though that such WikiLinks will not show up as
79 backlinks to the page that uses the template.
80
81 Note the use of "raw_name" inside the [[WikiLink]] generator. This ensures
82 that if the name contains something that might be mistaken for wiki markup,
83 it's not converted to html before being processed as a [[WikiLink]].