2 # Structured template plugin.
3 package IkiWiki::Plugin::template;
12 hook(type => "preprocess", id => "template", call => \&preprocess);
15 sub preprocess (@) { #{{{
18 if (! exists $params{id}) {
19 return "[[template missing id parameter]]"
22 my $template_page="templates/$params{id}";
23 add_depends($params{page}, $template_page);
25 my $template_file=$pagesources{$template_page};
27 htmllink($params{page}, $params{destpage}, $template_page).
29 unless defined $template_file;
33 $template=HTML::Template->new(
36 $$text_ref=&Encode::decode_utf8($$text_ref);
39 filename => srcfile($template_file),
40 die_on_bad_params => 0,
46 return "[[template failed to process: $@]]";
49 foreach my $param (keys %params) {
50 $template->param($param => $params{$param});
53 return IkiWiki::preprocess($params{page}, $params{destpage},