move template documentation into the basewiki, in the templates page
[ikiwiki] / 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 These templates are available for inclusion onto other pages in this
11 wiki:
12
13 [[inline pages="templates/* and !*/discussion" feeds=no archive=yes
14 sort=title template=titlepage]]
15 """]]
16
17 Using a template works like this:
18
19         \[[template id=note text="""Here is the text to insert into my note."""]]
20
21 This fills out the [[note]] template, filling in the `text` field with
22 the specified value, and inserts the result into the page.
23
24 A value can include any markup that would be allowed in the wiki page
25 outside the template. Triple-quoting the value even allows quotes to be
26 included in it. Combined with multi-line quoted values, this allows for
27 large chunks of marked up text to be embedded into a template:
28
29         \[[template id=foo name="Sally" color="green" age=8 notes="""
30         * \[[Charley]]'s sister.
31         * "I want to be an astronaut when I grow up."
32         * Really 8 and a half.
33         """]]
34
35 To create a template, simply add a template directive to a page, and page will
36 provide a link that can be used to create the template. The template is a
37 regular wiki page, located in the `templates/` directory.
38
39 The template uses the syntax used by the
40 [cpan HTML::Template](http://search.cpan.org/search?mode=dist&query=HTML::Template)
41 perl module, which allows for some fairly complex things to be done.
42 Consult its documentation for the full syntax, but all you really need to know
43 are a few things:
44
45 * To insert the value of a variable, use `<TMPL_VAR variable>`.
46 * To make a block of text conditional on a variable being set use
47   `<TMPL_IF NAME="variable">text</TMPL_IF>`.
48 * To use one block of text if a variable is set and a second if it's not,
49   use `<TMPL_IF NAME="variable">text<TMPL_ELSE>other text</TMPL_IF>`
50
51 Here's a sample template:
52
53         <span class="infobox">
54         Name: <TMPL_VAR name><br />
55         Age: <TMPL_VAR age><br />
56         <TMPL_IF NAME="color">
57         Favorite color: <TMPL_VAR color><br />
58         <TMPL_ELSE>
59         No favorite color.<br />
60         </TMPL_IF>
61         <TMPL_IF NAME="notes">
62         <hr />
63         <TMPL_VAR notes>
64         </TMPL_IF>
65         </span>
66
67 The filled out template will be formatted the same as the rest of the page
68 that contains it, so you can include WikiLinks and all other forms of wiki
69 markup in the template. Note though that such WikiLinks will not show up as
70 backlinks to the page that uses the template.