1 [[!template id=plugin name=field author="[[rubykat]]"]]
6 IkiWiki::Plugin::field - front-end for per-page record fields.
11 add_plugins => [qw{goodstuff field ....}],
14 field_register => [qw{meta}],
16 # simple registration with priority
22 # allow the config to be queried as a field
23 field_allow_config => 1,
25 # flag certain fields as "tags"
27 BookAuthor => '/books/authors',
28 BookGenre => '/books/genres',
29 MovieGenre => '/movies/genres',
34 This plugin is meant to be used in conjunction with other plugins
35 in order to provide a uniform interface to access per-page structured
36 data, where each page is treated like a record, and the structured data
37 are fields in that record. This can include the meta-data for that page,
38 such as the page title.
40 Plugins can register a function which will return the value of a "field" for
41 a given page. This can be used in a few ways:
43 * In page templates; all registered fields will be passed to the page template in the "pagetemplate" processing.
44 * In PageSpecs; the "field" function can be used to match the value of a field in a page.
45 * In SortSpecs; the "field" function can be used for sorting pages by the value of a field in a page.
46 * 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.
48 ## CONFIGURATION OPTIONS
50 The following options can be set in the ikiwiki setup file.
52 **field_allow_config**
54 field_allow_config => 1,
56 Allow the $config hash to be queried like any other field; the
57 keys of the config hash are the field names.
61 field_register => [qw{meta}],
68 A hash of plugin-IDs to register. The keys of the hash are the names of the
69 plugins, and the values of the hash give the order of lookup of the field
70 values. The order can be 'first', 'last', 'middle', or an explicit order
71 sequence between 'AA' and 'ZZ'. If the simpler type of registration is used,
72 then the order will be 'middle'.
74 This assumes that the plugins in question store data in the %pagestatus hash
75 using the ID of that plugin, and thus the field values are looked for there.
77 This is the simplest form of registration, but the advantage is that it
78 doesn't require the plugin to be modified in order for it to be
79 registered with the "field" plugin.
84 BookAuthor => '/books/authors',
85 BookGenre => '/books/genres',
86 MovieGenre => '/movies/genres',
89 A hash of fields and their associated pages. This provides a faceted
92 The way this works is that a given field-name will be associated with a given
93 page, and the values of that field will be linked to sub-pages of that page.
99 will link to "/books/genres/SF", with a link-type of "bookgenre".
103 The `field` plugin provides a few PageSpec functions to match values
107 * **field(*name* *glob*)**
108 * field(bar Foo\*) will match if the "bar" field starts with "Foo".
110 * **destfield(*name* *glob*)**
111 * as for "field" but matches against the destination page (i.e when the source page is being included in another page).
113 * **field_item(*name* *glob*)**
114 * field_item(bar Foo) will match if one of the values of the "bar" field is "Foo".
116 * **destfield_item(*name* *glob*)**
117 * as for "field_item" but matches against the destination page.
119 * **field_tagged(*name* *glob*)**
120 * like `tagged`, but this uses the tag-bases and link-types defined in the `field_tags` configuration option.
122 * **destfield_tagged(*name* *glob*)**
123 * as for "field_tagged" but matches against the destination page.
127 The "field" SortSpec function can be used to sort a page depending on the value of a field for that page. This is used for directives that take sort parameters, such as **inline** or **report**.
133 sort="field(bar)" will sort by the value og the "bar" field.
139 field_register(id=>$id);
141 Register a plugin as having field data. The above form is the simplest, where
142 the field value is looked up in the %pagestatus hash under the plugin-id.
148 A reference to a function to call rather than just looking up the value in the
149 %pagestatus hash. It takes two arguments: the name of the field, and the name
150 of the page. It is expected to return (a) an array of the values of that field
151 if "wantarray" is true, or (b) a concatenation of the values of that field
152 if "wantarray" is not true, or (c) undef if there is no field by that name.
160 return (wantarray ? @values : $value);
165 Set this to be called first in the sequence of calls looking for values. Since
166 the first found value is the one which is returned, ordering is significant.
167 This is equivalent to "order=>'first'".
171 Set this to be called last in the sequence of calls looking for values. Since
172 the first found value is the one which is returned, ordering is significant.
173 This is equivalent to "order=>'last'".
177 Set the explicit ordering in the sequence of calls looking for values. Since
178 the first found value is the one which is returned, ordering is significant.
180 The values allowed for this are "first", "last", "middle", or a two-character
181 ordering-sequence between 'AA' and 'ZZ'.
183 ### field_get_value($field, $page)
185 my @values = field_get_value($field, $page);
187 my $value = field_get_value($field, $page);
189 Returns the values of the field for that page, or undef if none is found.
190 Note that it will return an array of values if you ask for an array,
191 and a scalar value if you ask for a scalar.
195 * browse at GitHub: <http://github.com/rubykat/ikiplugins/blob/master/IkiWiki/Plugin/field.pm>
196 * git repo at git://github.com/rubykat/ikiplugins.git