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