2007-10-02 08:20:25 +02:00
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
2008-10-02 23:43:03 +02:00
[[!tag patch]]
2007-10-25 01:03:36 +02:00
2007-10-02 08:20:25 +02:00
#!/usr/bin/perl
package IkiWiki::Plugin::tmplvars;
use warnings;
use strict;
use IkiWiki 2.00;
my %tmplvars;
2008-12-17 21:22:16 +01:00
sub import {
2007-10-02 08:20:25 +02:00
hook(type => "preprocess", id => "tmplvars", call => \&preprocess);
hook(type => "pagetemplate", id => "tmplvars", call => \&pagetemplate);
2008-12-17 21:22:16 +01:00
}
2007-10-02 08:20:25 +02:00
2008-12-17 21:22:16 +01:00
sub preprocess (@) {
2007-10-02 08:20:25 +02:00
my %params=@_;
if ($params{page} eq $params{destpage}) {
my $page = $params{page};
if (undef $tmplvars{$page}){
$tmplvars{$page} = {};
}
# XXX: The only way to get at just the user-specified params is
# to try to remove all the Ikiwiki-supplied ones.
delete $params{page};
delete $params{destpage};
delete $params{preview};
foreach my $arg (keys %params){
$tmplvars{$page}->{$arg} = $params{$arg};
}
}
2008-12-17 21:22:16 +01:00
}
2007-10-02 08:20:25 +02:00
2008-12-17 21:22:16 +01:00
sub pagetemplate (@) {
2007-10-02 08:20:25 +02:00
my %params=@_;
my $template = $params{template};
if (exists $tmplvars{$params{page}}) {
foreach my $arg (keys %{$tmplvars{$params{page}}}){
$template->param($arg => $tmplvars{$params{page}}->{$arg});
}
}
return undef;
2008-12-17 21:22:16 +01:00
}
2007-10-02 08:20:25 +02:00
1