From 40959ce76d159cefaf0431ad2cc61ad35a9f99b1 Mon Sep 17 00:00:00 2001 From: joey Date: Thu, 26 Jul 2007 20:50:55 +0000 Subject: * Add templatefile hook. * Add pagetemplate plugin, which allows changing the template used for a page. (Not to be confused with the hook of the same name..) --- IkiWiki/Plugin/pagetemplate.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 IkiWiki/Plugin/pagetemplate.pm (limited to 'IkiWiki/Plugin/pagetemplate.pm') diff --git a/IkiWiki/Plugin/pagetemplate.pm b/IkiWiki/Plugin/pagetemplate.pm new file mode 100644 index 000000000..b5ebf623d --- /dev/null +++ b/IkiWiki/Plugin/pagetemplate.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::pagetemplate; + +use warnings; +use strict; +use IkiWiki 2.00; + +my %templates; + +sub import { #{{{ + hook(type => "preprocess", id => "pagetemplate", call => \&preprocess); + hook(type => "templatefile", id => "pagetemplate", call => \&templatefile); +} # }}} + +sub preprocess (@) { #{{{ + my %params=@_; + + if (! exists $params{template} || + $params{template} !~ /^[-A-Za-z0-9._+]+$/ || + ! defined IkiWiki::template_file($params{template})) { + return "[[pagetemplate ".gettext("bad or missing template")."]]"; + } + + if ($params{page} eq $params{destpage}) { + $templates{$params{page}}=$params{template}; + } + +} # }}} + +sub templatefile (@) { #{{{ + my %params=@_; + + if (exists $templates{$params{page}}) { + return $templates{$params{page}}; + } + + return undef; +} # }}} + +1 -- cgit v1.2.3