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 ".gettext("missing id parameter")."]]";
22 my $template_page="templates/$params{id}";
23 add_depends($params{page}, $template_page);
25 my $template_file=$pagesources{$template_page};
26 return sprintf(gettext("template %s not found"),
27 htmllink($params{page}, $params{destpage}, $template_page))
28 unless defined $template_file;
32 $template=HTML::Template->new(
35 $$text_ref=&Encode::decode_utf8($$text_ref);
38 filename => srcfile($template_file),
39 die_on_bad_params => 0,
45 return "[[template ".gettext("failed to process:")." $@]]";
48 foreach my $param (keys %params) {
49 $template->param($param => $params{$param});
52 return IkiWiki::htmlize($params{page}, pagetype($pagesources{$params{page}}),
53 IkiWiki::preprocess($params{page}, $params{destpage},
54 IkiWiki::filter($params{page}, $params{destpage},