]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/contrib/field.mdwn
oops, fixed name
[ikiwiki.git] / doc / plugins / contrib / field.mdwn
1 [[!template id=plugin name=field author="[[rubykat]]"]]
2 [[!toc]]
3 ## NAME
4
5 IkiWiki::Plugin::field - front-end for per-page record fields.
6
7 ## SYNOPSIS
8
9     # activate the plugin
10     add_plugins => [qw{goodstuff field ....}],
11
12     # simple registration
13     field_register => [qw{meta}],
14
15 ## DESCRIPTION
16
17 This plugin is meant to be used in conjunction with other plugins
18 in order to provide a uniform interface to access per-page structured
19 data, where each page is treated like a record, and the structured data
20 are fields in that record.  This can include the meta-data for that page,
21 such as the page title.
22
23 Plugins can register a function which will return the value of a "field" for
24 a given page.  This can be used in three ways:
25
26 * In page templates; all registered fields will be passed to the page template in the "pagetemplate" processing.
27 * In PageSpecs; the "field" function can be used to match the value of a field in a page.
28 * By other plugins, using the field_get_value function, to get the value of a field for a page, and do with it what they will.
29
30 ## OPTIONS
31
32 The following options can be set in the ikiwiki setup file.
33
34 **field_register**
35
36 A list of plugin-IDs to register.  This assumes that the plugins in
37 question store data in the %pagestatus hash using the ID of that plugin,
38 and thus the field values are looked for there.
39
40 This is the simplest form of registration, but the advantage is that it
41 doesn't require the plugin to be modified in order for it to be
42 registered with the "field" plugin.
43
44 ## PageSpec
45
46 The "field" PageSpec function can be used to match the value of a field for a page.
47
48 field(*name* *glob*)
49
50 For example:
51
52 field(bar Foo*) will match if the "bar" field starts with "Foo".
53
54 ## FUNCTIONS
55
56 ### field_register
57
58 field_register(id=>$id);
59
60 Register a plugin as having field data.  The above form is the simplest, where the field value
61 is looked up in the %pagestatus hash under the plugin-id.
62
63 Additional Options:
64
65 **call=>&myfunc**
66
67 A reference to a function to call rather than just looking up the value in the %pagestatus hash.
68 It takes two arguments: the name of the field, and the name of the page.  It is expected to return
69 the value of that field, or undef if there is no field by that name.
70
71     sub myfunc ($$) {
72         my $field = shift;
73         my $page = shift;
74
75         ...
76
77         return $value;
78     }
79
80 **first=>1**
81
82 Set this to be called first in the sequence of calls looking for values.  Since the first found
83 value is the one which is returned, ordering is significant.
84
85 **last=>1**
86
87 Set this to be called last in the sequence of calls looking for values.  Since the first found
88 value is the one which is returned, ordering is significant.
89
90 ### field_get_value($field, $page)
91
92 Returns the value of the field for that page, or undef if none is found.
93
94 ## DOWNLOAD
95
96 * browse at GitHub: <http://github.com/rubykat/ikiplugins/blob/master/IkiWiki/Plugin/field.pm>
97 * git repo at git://github.com/rubykat/ikiplugins.git