Allow dots in parameter key names
[ikiwiki] / doc / plugins / contrib / getfield / discussion.mdwn
1 ## Multiple values arrays
2
3 This breaks if there are multiple values for a single key. It works fine in the report plugin, but inline display shows the ARRAY reference, e.g. 
4
5     IPv6:
6     - fd64:2c08:9fa7:4::1
7     - 2001:470:1d:4a6::1
8
9 and:
10
11     {{$IPv6}}
12
13 yields:
14
15     ARRAY(0x266db10)
16
17 Seems to me this could be checked and `join(" ")`'d. :) -- [[anarcat]]
18
19 > I wrote a stupid fix for this, which works for getfield, but isn't as good for report. It simply does that `join()`. Here's the patch:
20
21 > [[!format diff """
22 --- a/IkiWiki/Plugin/field.pm
23 +++ b/IkiWiki/Plugin/field.pm
24 @@ -322,6 +322,9 @@ sub field_get_value ($$;@) {
25      {
26         $basevalue = calculated_values($lc_field_name, $page);
27      }
28 +    if (ref($basevalue) eq "ARRAY") {
29 +        $basevalue = join(" ", @{$basevalue}); # hack
30 +    }
31      if (defined $basevalue)
32      {
33         $Cache{$page}{$basename} = $basevalue;
34 @@ -360,6 +363,9 @@ sub field_get_value ($$;@) {
35      {
36         $value = $basevalue;
37      }
38 +    if (ref($value) eq "ARRAY") {
39 +        $value = join(" ", @{$value}); # hack
40 +    }
41      if (defined $value)
42      {
43         $Cache{$page}{$lc_field_name} = $value;
44 """]]
45 >
46 > Seems to me this should be the default, at the very least in getfield. But at least, with the above patch we don't see expanded Perl ref's. ;) --[[anarcat]]
47
48 ## Templating, and other uses
49
50 Like you mentioned in [[ftemplate]] IIRC, it'll only work on the same page. If it can be made to work anywhere, or from a specific place in the wiki - configurable, possibly - you'll have something very similar to mediawiki's templates. I can already think of a few uses for this combined with [[template]] ;) . --[[SR|users/simonraven]]
51
52 > Yes, I mentioned "only current page" in the "LIMITATIONS" section.
53
54 > What do you think would be a good syntax for querying other pages?
55 > It needs to resolve to a single page, though I guess using "bestlink" to find the closest page would mean that one didn't have to spell out the whole page.
56
57 >> I don't know the internals very well, I think that's how other plugins do it. *goes to check* Usually it's a `foreach` loop, and use a `pagestate{foo}` to check the page's status/state. There's also some stuff like 'pagespec_match_list($params{page}` ... they do slightly different thing depending on need. --[[SR|users/simonraven]]
58
59 >>> No, I meant what markup I should use; the actual implementation probably wouldn't be too difficult.
60
61 >>> The current markup is {{$*fieldname*}}; what you're wanting, perhaps it should be represented like {{$*pagename*:*fieldname*}}, or {{$*pagename*::*fieldname*}} or something else...
62 >>> -- [[KathrynAndersen]]
63
64 >>>> Oh. Hmm. I like your idea actually, or alternately, in keeping more with other plugins, doing it like {{pagename/fieldname}}. The meaning of the separator is less clear with /, but avoids potential issues with filename clashes that have a colon in them. It also keeps a certain logic - at least to me. Either way, I think both are good choices. [[SR|users/simonraven]]
65
66 >>>>> What about using {{pagename#fieldname}}? The meaning of the hash in URLs sort of fits with what is needed here (reference to a 'named' thing within the page) and it won't conflict with actual hash usages (unless we expect different named parts of pages to define different values for the same field ...)
67 >>>>> -- [[Oblomov]]
68 >>>>>> That's a good one too. --[[simonraven]]
69 >>>>>>> Done!  I used {{$*pagename*#*fieldname*}} for the format. -- [[users/KathrynAndersen]]
70
71
72 > I'm also working on a "report" plugin, which will basically apply a template like [[ftemplate]] does, but to a list of pages given from a pagespec, rather than the current page.
73
74 > -- [[users/KathrynAndersen]]
75
76 >> Ooh, sounds nice :) . --[[SR|users/simonraven]]
77
78 >>> I've now released the [[plugins/contrib/report]] plugin.  I've been using it on my site; the holdup on releasing was because I hadn't yet written the docs for it. I hope you find it useful.
79 >>> -- [[users/KathrynAndersen]]