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 # This needs to run even in scan mode, in order to process
29 # links and other metadata included via the template.
30 my $scan=! defined wantarray;
32 if (! exists $params{id}) {
33 error gettext("missing id parameter")
36 my $template_page="templates/$params{id}";
37 add_depends($params{page}, $template_page);
39 my $template_file=$pagesources{$template_page};
40 return sprintf(gettext("template %s not found"),
41 htmllink($params{page}, $params{destpage}, "/".$template_page))
42 unless defined $template_file;
46 $template=HTML::Template->new(
49 $$text_ref=&Encode::decode_utf8($$text_ref);
52 filename => srcfile($template_file),
53 die_on_bad_params => 0,
59 error gettext("failed to process:")." $@"
62 $params{basename}=IkiWiki::basename($params{page});
64 foreach my $param (keys %params) {
65 my $value=IkiWiki::preprocess($params{page}, $params{destpage},
66 IkiWiki::filter($params{page}, $params{destpagea},
67 $params{$param}), $scan);
68 if ($template->query(name => $param)) {
69 $template->param($param =>
70 IkiWiki::htmlize($params{page}, $params{destpage},
71 pagetype($pagesources{$params{page}}),
74 if ($template->query(name => "raw_$param")) {
75 $template->param("raw_$param" => $value);
79 return IkiWiki::preprocess($params{page}, $params{destpage},
80 IkiWiki::filter($params{page}, $params{destpage},
81 $template->output), $scan);