aboutsummaryrefslogtreecommitdiff
path: root/doc/plugins/contrib/getfield.mdwn
blob: 61e80c58a76989e393850c640551da471a89c6c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
[[!template id=plugin name=getfield author="[[rubykat]]"]]
[[!tag type/meta type/format]]
[[!toc]]
## NAME

IkiWiki::Plugin::getfield - query the values of fields

## SYNOPSIS

    # activate the plugin
    add_plugins => [qw{goodstuff getfield ....}],

## DESCRIPTION

This plugin provides a way of querying the meta-data (data fields) of a page
inside the page content (rather than inside a template) This provides a way to
use per-page structured data, where each page is treated like a record, and the
structured data are fields in that record.  This can include the meta-data for
that page, such as the page title.

This plugin is meant to be used in conjunction with the [[field]] plugin.

### USAGE

One can get the value of a field by using special markup in the page.
This does not use directive markup, in order to make it easier to
use the markup inside other directives.  There are four forms:

* \{{$*fieldname*}}

  This queries the value of *fieldname* for the source page.

  For example:

    	\[[!meta title="My Long and Complicated Title With Potential For Spelling Mistakes"]]
    	# {{$title}}

  When the page is processed, this will give you:

    	<h1>My Long and Complicated Title With Potential For Spelling Mistakes</h1>

* \{{$*pagename*#*fieldname*}}

  This queries the value of *fieldname* for the page *pagename*.

  For example:

  On PageFoo:

    \[[!meta title="I Am Page Foo"]]

    Stuff about Foo.

  On PageBar:

    For more info, see \[[\{{$PageFoo#title}}|PageFoo]].

  When PageBar is displayed:

    &lt;p&gt;For more info, see &lt;a href="PageFoo"&gt;I Am Page Foo&lt;/a&gt;.&lt;/p&gt;

* \{{+$*fieldname*+}}

  This queries the value of *fieldname* for the destination page; that is,
  the value when this page is included inside another page.

  For example:

  On PageA:

    	\[[!meta title="I Am Page A"]]
    	# {{+$title+}}

    	Stuff about A.

  On PageB:

    	\[[!meta title="I Am Page B"]]
    	\[[!inline pagespec="PageA"]]

  When PageA is displayed:

    	<h1>I Am Page A</h1>
    	<p>Stuff about A.</p>

  When PageB is displayed:

    	<h1>I Am Page B</h1>
    	<p>Stuff about A.</p>

* \{{+$*pagename*#*fieldname*+}}

  This queries the value of *fieldname* for the page *pagename*; the
  only difference between this and \{{$*pagename*#*fieldname*}} is
  that the full name of *pagename* is calculated relative to the
  destination page rather than the source page.

  I can't really think of a reason why this should be needed, but
  this format has been added for completeness.

### Escaping

Getfield markup can be escaped by putting a backwards slash `\`
in front of the markup.
If that is done, then the markup is displayed as-is.

### No Value Found

If no value is found for the given field, then the field name is returned.

For example:

On PageFoo:

    \[[!meta title="Foo"]]
    My title is {{$title}}.
    
    My description is {{$description}}.

When PageFoo is displayed:

    <p>My title is Foo.</p>
    
    <p>My description is description.</p>

This is because "description" hasn't been defined for that page.

### More Examples

Listing all the sub-pages of the current page:

    \[[!map pages="{{$page}}/*"]]

## DOWNLOAD

* browse at GitHub: <http://github.com/rubykat/ikiplugins/blob/master/IkiWiki/Plugin/getfield.pm>
* git repo at git://github.com/rubykat/ikiplugins.git