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 can be used as
40 $template=template_depends($params{id}, $params{page},
44 # gettext can clobber $@
46 error sprintf(gettext("failed to process template %s"),
47 htmllink($params{page}, $params{destpage},
48 "/templates/$params{id}"))." $error";
51 $params{basename}=IkiWiki::basename($params{page});
53 foreach my $param (keys %params) {
54 my $value=IkiWiki::preprocess($params{page}, $params{destpage},
55 $params{$param}, $scan);
56 if ($template->query(name => $param)) {
57 my $htmlvalue=IkiWiki::htmlize($params{page}, $params{destpage},
58 pagetype($pagesources{$params{page}}),
61 $template->param($param => $htmlvalue);
63 if ($template->query(name => "raw_$param")) {
65 $template->param("raw_$param" => $value);
69 return IkiWiki::preprocess($params{page}, $params{destpage},
70 $template->output, $scan);