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);
16 sub getsetup () { #{{{
24 sub preprocess (@) { #{{{
27 if (! exists $params{id}) {
28 error gettext("missing id parameter")
31 my $template_page="templates/$params{id}";
32 add_depends($params{page}, $template_page);
34 my $template_file=$pagesources{$template_page};
35 return sprintf(gettext("template %s not found"),
36 htmllink($params{page}, $params{destpage}, $template_page))
37 unless defined $template_file;
41 $template=HTML::Template->new(
44 $$text_ref=&Encode::decode_utf8($$text_ref);
47 filename => srcfile($template_file),
48 die_on_bad_params => 0,
54 error gettext("failed to process:")." $@"
57 $params{basename}=IkiWiki::basename($params{page});
59 foreach my $param (keys %params) {
60 if ($template->query(name => $param)) {
61 $template->param($param =>
62 IkiWiki::htmlize($params{page}, $params{destpage},
63 pagetype($pagesources{$params{page}}),
66 if ($template->query(name => "raw_$param")) {
67 $template->param("raw_$param" => $params{$param});
71 return IkiWiki::preprocess($params{page}, $params{destpage},
72 IkiWiki::filter($params{page}, $params{destpage},