2 # Structured template plugin.
3 package IkiWiki::Plugin::template;
12 hook(type => "getsetup", id => "template", call => \&getsetup);
13 hook(type => "preprocess", id => "template", call => \&preprocess,
28 if (! exists $params{id}) {
29 error gettext("missing id parameter")
32 my $template_page="templates/$params{id}";
33 add_depends($params{page}, $template_page);
35 my $template_file=$pagesources{$template_page};
36 return sprintf(gettext("template %s not found"),
37 htmllink($params{page}, $params{destpage}, "/".$template_page))
38 unless defined $template_file;
42 $template=HTML::Template->new(
45 $$text_ref=&Encode::decode_utf8($$text_ref);
48 filename => srcfile($template_file),
49 die_on_bad_params => 0,
55 error gettext("failed to process:")." $@"
58 $params{basename}=IkiWiki::basename($params{page});
60 foreach my $param (keys %params) {
61 if ($template->query(name => $param)) {
62 $template->param($param =>
63 IkiWiki::htmlize($params{page}, $params{destpage},
64 pagetype($pagesources{$params{page}}),
67 if ($template->query(name => "raw_$param")) {
68 $template->param("raw_$param" => $params{$param});
72 return IkiWiki::preprocess($params{page}, $params{destpage},
73 IkiWiki::filter($params{page}, $params{destpage},