From: Joey Hess Date: Fri, 23 Apr 2010 18:44:37 +0000 (-0400) Subject: allow a bare page name to be specified as a template X-Git-Tag: 3.20100427~50 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/54898d16d4c86fddcb1b5588eac67a729c14deeb allow a bare page name to be specified as a template --- diff --git a/IkiWiki.pm b/IkiWiki.pm index 0aaf60569..03441b594 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1653,9 +1653,18 @@ sub saveindex () { sub template_file ($) { my $name=shift; + + my $tpage="templates/$name"; + if ($name !~ /\.tmpl$/ && exists $pagesources{$tpage}) { + $tpage=$pagesources{$tpage}; + $name.=".tmpl"; + } - my $template=srcfile("templates/$name", 1); - return $template if defined $template; + my $template=srcfile($tpage, 1); + if (defined $template) { + return $template, $tpage if wantarray; + return $template; + } foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") { @@ -1664,18 +1673,16 @@ sub template_file ($) { return; } -sub template ($;@) { - template_depends(shift, undef, @_); -} - sub template_depends ($$;@) { my $name=shift; my $page=shift; - - if (defined $page) { - add_depends($page, "templates/$name"); + + my ($filename, $tpage)=template_file($name); + if (defined $page && defined $tpage) { + add_depends($page, $tpage); } - my $filename=template_file($name); + + return unless defined $filename; require HTML::Template; return HTML::Template->new( @@ -1691,6 +1698,10 @@ sub template_depends ($$;@) { ); } +sub template ($;@) { + template_depends(shift, undef, @_); +} + sub misctemplate ($$;@) { my $title=shift; my $pagebody=shift; diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index eaa008131..1407b5a12 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -702,8 +702,15 @@ the entire wiki build and make the wiki unusable. ### `template($;@)` Creates and returns a [[!cpan HTML::Template]] object. The first parameter -is the name of the file in the template directory. The optional remaining -parameters are passed to `HTML::Template->new`. +is the name of the template file. The optional remaining parameters are +passed to `HTML::Template->new`. + +The template file is first looked for in the templates/ subdirectory of the +srcdir. Failing that, it is looked for in the templatedir. Typically +the filename will have a ".tmpl" extension. If a filename with no extension +is passed, a wiki page in templates/ with its name is used as the template. +That should only be done for templates which it is safe to let wiki users +edit. ### `template_depends($$;@)` diff --git a/template-transition-notes b/template-transition-notes index 193dd79d4..ccff3e78f 100644 --- a/template-transition-notes +++ b/template-transition-notes @@ -3,3 +3,4 @@ * includes no longer allowed in templates * template directive no longer uses $foo.tmpl , only page $foo. +* template_params removed (not exported API)