2 # Structured template plugin.
3 package IkiWiki::Plugin::template;
11 hook(type => "getsetup", id => "template", call => \&getsetup);
12 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 # The bare id is used, so a page templates/$id will be used as
40 $template=template_depends($params{id}, $params{page},
44 error gettext("failed to process template:")." $@";
47 error sprintf(gettext("%s not found"),
48 htmllink($params{page}, $params{destpage},
49 "/templates/$params{id}"))
52 $params{basename}=IkiWiki::basename($params{page});
54 foreach my $param (keys %params) {
55 my $value=IkiWiki::preprocess($params{page}, $params{destpage},
56 IkiWiki::filter($params{page}, $params{destpagea},
57 $params{$param}), $scan);
58 if ($template->query(name => $param)) {
59 $template->param($param =>
60 IkiWiki::htmlize($params{page}, $params{destpage},
61 pagetype($pagesources{$params{page}}),
64 if ($template->query(name => "raw_$param")) {
65 $template->param("raw_$param" => $value);
69 return IkiWiki::preprocess($params{page}, $params{destpage},
70 IkiWiki::filter($params{page}, $params{destpage},
71 $template->output), $scan);