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") {
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(
);
}
+sub template ($;@) {
+ template_depends(shift, undef, @_);
+}
+
sub misctemplate ($$;@) {
my $title=shift;
my $pagebody=shift;
### `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($$;@)`