1 A simple plugin to allow per-page customization of a template by passing paramaters to HTML::Template. For those times when a whole pagetemplate is too much work. --Ethan
5 > The implementation looks fine to me (assuming it works with current ikiwiki),
6 > apart from the "XXX" already noted in the patch. The design could reasonably
7 > be considered premature generalization, though - how often do you actually
8 > need to define new tmplvars?
10 > As for the page/destpage/preview thing, it would be good if the preprocess
11 > hook could distinguish between software-supplied and user-supplied
12 > parameters (the [[plugins/tag]] plugin could benefit from this too). Perhaps
13 > the IkiWiki core could be modified so that
14 > `hook(type => "preprocess", splitparams => 1, ...)` would invoke preprocess
15 > with { page => "foo", destpage => "bar", ... } as a special first argument,
16 > and the user-supplied parameters as subsequent arguments? Then plugins like
19 > my $ikiparams = shift;
22 > add_tags($ikiparams->{page}, keys %params);
29 package IkiWiki::Plugin::tmplvars;
38 hook(type => "preprocess", id => "tmplvars", call => \&preprocess);
39 hook(type => "pagetemplate", id => "tmplvars", call => \&pagetemplate);
45 if ($params{page} eq $params{destpage}) {
46 my $page = $params{page};
47 if (undef $tmplvars{$page}){
48 $tmplvars{$page} = {};
50 # XXX: The only way to get at just the user-specified params is
51 # to try to remove all the Ikiwiki-supplied ones.
53 delete $params{destpage};
54 delete $params{preview};
55 foreach my $arg (keys %params){
56 $tmplvars{$page}->{$arg} = $params{$arg};
62 sub pagetemplate (@) {
64 my $template = $params{template};
66 if (exists $tmplvars{$params{page}}) {
67 foreach my $arg (keys %{$tmplvars{$params{page}}}){
68 $template->param($arg => $tmplvars{$params{page}}->{$arg});