allow a bare page name to be specified as a template

master
Joey Hess 2010-04-23 14:44:37 -04:00
parent 011d88052d
commit 54898d16d4
3 changed files with 31 additions and 12 deletions

View File

@ -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;

View File

@ -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($$;@)`

View File

@ -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)