aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-10-02 06:20:25 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-10-02 06:20:25 +0000
commitb339a9ebac97389454db8fa0c2c55eea7aa7137d (patch)
tree36cbad0c9cc04d17adf0eb270ef41ce3a26dee6b
parent37c6116d6aab664b5d6d4cb1f90f4c6bf8ed2558 (diff)
downloadikiwiki-b339a9ebac97389454db8fa0c2c55eea7aa7137d.tar
ikiwiki-b339a9ebac97389454db8fa0c2c55eea7aa7137d.tar.gz
web commit by http://ethan.betacantrips.com/: something I found useful
-rw-r--r--doc/todo/tmplvars_plugin.mdwn50
1 files changed, 50 insertions, 0 deletions
diff --git a/doc/todo/tmplvars_plugin.mdwn b/doc/todo/tmplvars_plugin.mdwn
new file mode 100644
index 000000000..b944fb8f6
--- /dev/null
+++ b/doc/todo/tmplvars_plugin.mdwn
@@ -0,0 +1,50 @@
+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
+
+ #!/usr/bin/perl
+ package IkiWiki::Plugin::tmplvars;
+
+ use warnings;
+ use strict;
+ use IkiWiki 2.00;
+
+ my %tmplvars;
+
+ sub import { #{{{
+ hook(type => "preprocess", id => "tmplvars", call => \&preprocess);
+ hook(type => "pagetemplate", id => "tmplvars", call => \&pagetemplate);
+ } # }}}
+
+ sub preprocess (@) { #{{{
+ 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};
+ }
+ }
+
+ } # }}}
+
+ sub pagetemplate (@) { #{{{
+ 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;
+ } # }}}
+
+ 1