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 # This needs to run even in scan mode, in order to process
73 # links and other metadata includes via the template.
74 my $scan=! defined wantarray;
76 return IkiWiki::preprocess($params{page}, $params{destpage},
77 IkiWiki::filter($params{page}, $params{destpage},
78 $template->output), $scan);