summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagetemplate.pm
blob: 69a2433a8ffb1d74119762c8d9aeae3e3cedae01 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::pagetemplate;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. my %templates;
  7. sub import { #{{{
  8. hook(type => "preprocess", id => "pagetemplate", call => \&preprocess);
  9. hook(type => "templatefile", id => "pagetemplate", call => \&templatefile);
  10. } # }}}
  11. sub preprocess (@) { #{{{
  12. my %params=@_;
  13. if (! exists $params{template} ||
  14. $params{template} !~ /^[-A-Za-z0-9._+]+$/ ||
  15. ! defined IkiWiki::template_file($params{template})) {
  16. return "[[pagetemplate ".gettext("bad or missing template")."]]";
  17. }
  18. if ($params{page} eq $params{destpage}) {
  19. $templates{$params{page}}=$params{template};
  20. }
  21. return "";
  22. } # }}}
  23. sub templatefile (@) { #{{{
  24. my %params=@_;
  25. if (exists $templates{$params{page}}) {
  26. return $templates{$params{page}};
  27. }
  28. return undef;
  29. } # }}}
  30. 1