c6e70e960691bfbeff23510e9019cd3273034a82
[ikiwiki.git] / doc / ikiwiki / directive / report.mdwn
1 The `report` directive is supplied by the [[!iki plugins/contrib/report desc=report]] plugin.
2
3 This enables one to report on the structured data ("field" values) of
4 multiple pages; the output is formatted via a template.  This depends
5 on the [[plugins/contrib/field]] plugin.
6
7 The pages to report on are selected by a PageSpec given by the "pages"
8 parameter.  The template is given by the "template" parameter.
9 The template expects the data from a single page; it is applied
10 to each matching page separately, one after the other.
11
12 Additional parameters can be used to fill out the template, in
13 addition to the "field" values.  Passed-in values override the
14 "field" values.
15
16 There are two places where template files can live.  One is in the
17 /templates directory on the wiki.  These templates are wiki pages, and
18 can be edited from the web like other wiki pages.
19
20 The second place where template files can live is in the global
21 templates directory (the same place where the page.tmpl template lives).
22 This is a useful place to put template files if you want to prevent
23 them being edited from the web, and you don't want to have to make
24 them work as wiki pages.
25
26 ## OPTIONS
27
28 **template**: The template to use for the report.
29
30 **pages**: A PageSpec to determine the pages to report on.
31
32 **trail**: A page or pages to use as a "trail" page.
33
34 When a trail page is used, the matching pages are limited to (a subset
35 of) the pages which that page links to; the "pages" pagespec in this
36 case, rather than selecting pages from the entire wiki, will select
37 pages from within the set of pages given by the trail page.
38
39 Additional space-separated trail pages can be given in this option.
40 For example:
41
42     trail="animals/cats animals/dogs"
43
44 This will take the links from both the "animals/cats" page and the
45 "animals/dogs" page as the set of pages to apply the PageSpec to.
46
47 **sort**: A SortSpec to determine how the matching pages should be sorted.
48
49 **here_only**: Report on the current page only.
50
51 This is useful in combination with "prev_" and "next_" variables to
52 make a navigation trail.
53 If the current page doesn't match the pagespec, then no pages will
54 be reported on.
55
56 ### Headers
57
58 An additional option is the "headers" option.  This is a space-separated
59 list of field names which are to be used as headers in the report.  This
60 is a way of getting around one of the limitations of HTML::Template, that
61 is, not being able to do tests such as
62 "if this-header is not equal to previous-header".
63
64 Instead, that logic is performed inside the plugin.  The template is
65 given parameters "HEADER1", "HEADER2" and so on, for each header.
66 If the value of a header field is the same as the previous value,
67 then HEADER**N** is set to be empty, but if the value of the header
68 field is new, then HEADER**N** is given that value.
69
70 #### Example
71
72 Suppose you're writing a blog in which you record "moods", and you
73 want to display your blog posts by mood.
74
75     \[[!report template="mood_summary"
76     pages="blog/*"
77     sort="Mood Date title"
78     headers="Mood"]]
79
80 The "mood_summary" template might be like this:
81
82     <TMPL_IF NAME="HEADER1">
83     ## <TMPL_VAR NAME="HEADER1">
84     </TMPL_IF>
85     ### <TMPL_VAR NAME="TITLE">
86     (<TMPL_VAR NAME="DATE">) \[[<TMPL_VAR NAME="PAGE">]]
87     <TMPL_VAR NAME="DESCRIPTION">
88     
89 ### Advanced Options
90
91 The following options are used to improve efficiency when dealing
92 with large numbers of pages; most people probably won't need them.
93
94 **doscan**:
95
96 Whether this report should be called in "scan" mode; if it is, then
97 the pages which match the pagespec are added to the list of links from
98 this page.  This can be used by *another* report by setting this
99 page to be a "trail" page in *that* report.
100 It is not possible to use "trail" and "doscan" at the same time.
101 By default, "doscan" is false.
102
103 ## TEMPLATE PARAMETERS
104
105 The templates are in HTML::Template format, just as [[plugins/template]] and
106 [[ftemplate]] are.  The parameters passed in to the template are as follows:
107
108 ### Fields
109
110 The structured data from the current matching page.  This includes
111 "title" and "description" if they are defined.
112
113 ### Common values
114
115 Values known for all pages: "page", "destpage".  Also "basename" (the
116 base name of the page).
117
118 ### Passed-in values
119
120 Any additional parameters to the report directive are passed to the
121 template; a parameter will override the matching "field" value.
122 For example, if you have a "Mood" field, and you pass Mood="bad" to
123 the report, then that will be the Mood which is given for the whole
124 report.
125
126 Generally this is useful if one wishes to make a more generic
127 template and hide or show portions of it depending on what
128 values are passed in the report directive call.
129
130 For example, one could have a "hide_mood" parameter which would hide
131 the "Mood" section of your template when it is true, which one could
132 use when the Mood is one of the headers.
133
134 ### Prev_ And Next_ Items
135
136 Any of the above variables can be prefixed with "prev_" or "next_"
137 and that will give the previous or next value of that variable; that is,
138 the value from the previous or next page that this report is reporting on.
139 This is mainly useful for a "here_only" report.
140
141 ### Headers
142
143 See the section on Headers.
144
145 ### First and Last
146
147 If this is the first page-record in the report, then "first" is true.
148 If this is the last page-record in the report, then "last" is true.