]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/template.pm
* Yet another fix for those poor case-insensative `OSX users.
[git.ikiwiki.info.git] / IkiWiki / Plugin / template.pm
1 #!/usr/bin/perl
2 # Structured template plugin.
3 package IkiWiki::Plugin::template;
5 use warnings;
6 use strict;
7 use IkiWiki;
8 use HTML::Template;
9 use Encode;
11 sub import { #{{{
12         hook(type => "preprocess", id => "template", call => \&preprocess);
13 } # }}}
15 sub preprocess (@) { #{{{
16         my %params=@_;
18         if (! exists $params{id}) {
19                 return "[[template missing id parameter]]"
20         }
22         my $template_page="templates/$params{id}";
23         add_depends($params{page}, $template_page);
25         my $template_file=$pagesources{$template_page};
26         return "[[template ".
27                htmllink($params{page}, $params{destpage}, $template_page).
28                " not found]]"
29                 unless defined $template_file;
31         my $template=HTML::Template->new(
32                 filter => sub {
33                         my $text_ref = shift;
34                         $$text_ref=&Encode::decode_utf8($$text_ref);
35                         chomp $$text_ref;
36                 },
37                 filename => srcfile($template_file),
38                 die_on_bad_params => 0,
39                 no_includes => 1,
40                 blind_cache => 1,
41         );
43         foreach my $param (keys %params) {
44                 $template->param($param => $params{$param});
45         }
47         return IkiWiki::preprocess($params{page}, $params{destpage},
48                 $template->output);
49 } # }}}
51 1