]> git.cworth.org Git - obsolete/notmuch-wiki/blob - templates.mdwn
Update news & manpages to notmuch version 0.16
[obsolete/notmuch-wiki] / templates.mdwn
1 [[!meta robots="noindex, follow"]]
2 [[!if test="enabled(template)"
3 then="This wiki has templates **enabled**."
4 else="This wiki has templates **disabled**."
5 ]]
6
7 Templates are files that can be filled out and inserted into pages in the
8 wiki.
9
10 [[!if test="enabled(template) and enabled(inline)" then="""
11
12 These templates are available for inclusion onto other pages in this
13 wiki:
14
15 [[!inline pages="templates/* and !*/discussion" feeds=no archive=yes
16 sort=title template=titlepage]]
17 """]]
18
19 ## Using a template
20
21 Using a template works like this:
22
23         \[[!template id=note text="""Here is the text to insert into my note."""]]
24
25 This fills out the [[note]] template, filling in the `text` field with
26 the specified value, and inserts the result into the page.
27
28 Generally, a value can include any markup that would be allowed in the wiki
29 page outside the template. Triple-quoting the value even allows quotes to
30 be included in it. Combined with multi-line quoted values, this allows for
31 large chunks of marked up text to be embedded into a template:
32
33         \[[!template id=foo name="Sally" color="green" age=8 notes="""
34         * \[[Charley]]'s sister.
35         * "I want to be an astronaut when I grow up."
36         * Really 8 and a half.
37         """]]
38
39 ## Creating a template
40
41 To create a template, simply add a template directive to a page, and the 
42 page will provide a link that can be used to create the template. The template
43 is a regular wiki page, located in the `templates/` subdirectory inside
44 the source directory of the wiki.
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 * Each parameter you pass to the template directive will generate a 
52   template variable. There are also some pre-defined variables like PAGE
53   and BASENAME.
54 * To insert the value of a variable, use `<TMPL_VAR variable>`. Wiki markup
55   in the value will first be converted to html.
56 * To insert the raw value of a variable, with wiki markup not yet converted
57   to html, use `<TMPL_VAR raw_variable>`.
58 * To make a block of text conditional on a variable being set use
59   `<TMPL_IF NAME="variable">text</TMPL_IF>`.
60 * To use one block of text if a variable is set and a second if it's not,
61   use `<TMPL_IF NAME="variable">text<TMPL_ELSE>other text</TMPL_IF>`
62
63 Here's a sample template:
64
65         <span class="infobox">
66         Name: \[[<TMPL_VAR raw_name>]]<br />
67         Age: <TMPL_VAR age><br />
68         <TMPL_IF NAME="color">
69         Favorite color: <TMPL_VAR color><br />
70         <TMPL_ELSE>
71         No favorite color.<br />
72         </TMPL_IF>
73         <TMPL_IF NAME="notes">
74         <hr />
75         <TMPL_VAR notes>
76         </TMPL_IF>
77         </span>
78
79 The filled out template will be formatted the same as the rest of the page
80 that contains it, so you can include WikiLinks and all other forms of wiki
81 markup in the template. Note though that such WikiLinks will not show up as
82 backlinks to the page that uses the template.
83
84 Note the use of "raw_name" inside the [[ikiwiki/WikiLink]] generator. This
85 ensures that if the name contains something that might be mistaken for wiki
86 markup, it's not converted to html before being processed as a
87 [[ikiwiki/WikiLink]].