1 [[!template id=plugin name=report author="[[rubykat]]"]]
2 [[!tag type/meta type/format]]
6 IkiWiki::Plugin::report - Produce templated reports from page field data.
11 add_plugins => [qw{goodstuff report ....}],
13 \[[!report template="blog_summary"
19 This plugin provides the **report** directive. This enables one to report on
20 the structured data ("field" values) of multiple pages; the output is formatted
21 via a template. This depends on the [[plugins/contrib/field]] plugin.
23 The pages to report on are selected by a PageSpec given by the "pages"
24 parameter. The template is given by the "template" parameter.
25 The template expects the data from a single page; it is applied
26 to each matching page separately, one after the other.
28 Additional parameters can be used to fill out the template, in
29 addition to the "field" values. Passed-in values override the
32 There are two places where template files can live. One, as with the
33 [[plugins/template]] plugin, is in the /templates directory on the wiki. These
34 templates are wiki pages, and can be edited from the web like other wiki
37 The second place where template files can live is in the global
38 templates directory (the same place where the page.tmpl template lives).
39 This is a useful place to put template files if you want to prevent
40 them being edited from the web, and you don't want to have to make
41 them work as wiki pages.
45 **template**: The template to use for the report.
47 **pages**: A PageSpec to determine the pages to report on.
49 **sort**: How the matching pages should be sorted. Sorting criteria are separated by spaces.
51 The possible values for sorting are:
53 * **page**: Sort by the full page ID.
54 * **pagename**: Sort by the base page name.
55 * **pagename_natural**: Sort by the base page name, using Sort::Naturally if it is installed.
56 * **mtime**: Sort by the page modification time.
57 * **age**: Sort by the page creation time, newest first.
59 Any other value is taken to be a field name to sort by.
60 If a sort value begins with a minus (-) then the order for that field is reversed.
64 An additional option is the "headers" option. This is a space-separated
65 list of field names which are to be used as headers in the report. This
66 is a way of getting around one of the limitations of HTML::Template, that
67 is, not being able to do tests such as
68 "if this-header is not equal to previous-header".
70 Instead, that logic is performed inside the plugin. The template is
71 given parameters "HEADER1", "HEADER2" and so on, for each header.
72 If the value of a header field is the same as the previous value,
73 then HEADER**N** is set to be empty, but if the value of the header
74 field is new, then HEADER**N** is given that value.
78 Suppose you're writing a blog in which you record "moods", and you
79 want to display your blog posts by mood.
81 \[[!report template="mood_summary"
83 sort="Mood Date title"
86 The "mood_summary" template might be like this:
88 <TMPL_IF NAME="HEADER1">
89 ## <TMPL_VAR NAME="HEADER1">
91 ### <TMPL_VAR NAME="TITLE">
92 (<TMPL_VAR NAME="DATE">) \[[<TMPL_VAR NAME="PAGE">]]
93 <TMPL_VAR NAME="DESCRIPTION">
97 The following options are used to improve efficiency when dealing
98 with large numbers of pages; most people probably won't need them.
102 A page or pages to use as a "trail" page. When a trail page is used,
103 the matching pages are limited to (a subset of) the pages which that
104 page links to; the "pages" pagespec in this case, rather than selecting
105 pages from the entire wiki, will select pages from within the set of pages
106 given by the trail page.
110 Whether this report should be called in "scan" mode; if it is, then
111 the pages which match the pagespec are added to the list of links from
112 this page. This can be used by *another* report by setting this
113 page to be a "trail" page in *that* report.
114 It is not possible to use "trail" and "doscan" at the same time.
115 By default, "doscan" is false.
117 ## TEMPLATE PARAMETERS
119 The templates are in HTML::Template format, just as [[plugins/template]] and
120 [[ftemplate]] are. The parameters passed in to the template are as follows:
124 The structured data from the current matching page. This includes
125 "title" and "description" if they are defined.
129 Values known for all pages: "page", "destpage". Also "basename" (the base name of the page).
131 ***passed-in values***:
133 Any additional parameters to the report directive are passed to the
134 template; a parameter will override the matching "field" value.
135 For example, if you have a "Mood" field, and you pass Mood="bad" to
136 the report, then that will be the Mood which is given for the whole
139 Generally this is useful if one wishes to make a more generic
140 template and hide or show portions of it depending on what
141 values are passed in the report directive call.
143 For example, one could have a "hide_mood" parameter which would hide
144 the "Mood" section of your template when it is true, which one could
145 use when the Mood is one of the headers.
149 See the section on Headers.
151 ***first and last***:
153 If this is the first page-record in the report, then "first" is true.
154 If this is the last page-record in the report, then "last" is true.
159 IkiWiki::Plugin::field
165 * browse at GitHub: <http://github.com/rubykat/ikiplugins/blob/master/IkiWiki/Plugin/report.pm>
166 * git repo at git://github.com/rubykat/ikiplugins.git