diff options
author | Joey Hess <joey@kitenet.net> | 2010-04-23 14:44:37 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-04-23 14:44:37 -0400 |
commit | 54898d16d4c86fddcb1b5588eac67a729c14deeb (patch) | |
tree | fd401da58dda87274edd5b0eac308c86819c3564 | |
parent | 011d88052d6dacb6a9d84b1489d37eefeb992da1 (diff) | |
download | ikiwiki-54898d16d4c86fddcb1b5588eac67a729c14deeb.tar ikiwiki-54898d16d4c86fddcb1b5588eac67a729c14deeb.tar.gz |
allow a bare page name to be specified as a template
-rw-r--r-- | IkiWiki.pm | 31 | ||||
-rw-r--r-- | doc/plugins/write.mdwn | 11 | ||||
-rw-r--r-- | template-transition-notes | 1 |
3 files changed, 31 insertions, 12 deletions
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) |