template: Search for templates in the templatedir, if they are not found as pages in the wiki.

master
Joey Hess 2010-04-02 16:54:06 -04:00
parent 1c8ac7d88c
commit 59ba938822
5 changed files with 22 additions and 4 deletions

View File

@ -37,7 +37,13 @@ sub preprocess (@) {
my $template_page="templates/$params{id}"; my $template_page="templates/$params{id}";
add_depends($params{page}, $template_page); add_depends($params{page}, $template_page);
my $template_file=$pagesources{$template_page}; my $template_file;
if (exists $pagesources{$template_page}) {
$template_file=srcfile($pagesources{$template_page});
}
else {
$template_file=template_file("$params{id}.tmpl")
}
return sprintf(gettext("template %s not found"), return sprintf(gettext("template %s not found"),
htmllink($params{page}, $params{destpage}, "/".$template_page)) htmllink($params{page}, $params{destpage}, "/".$template_page))
unless defined $template_file; unless defined $template_file;
@ -50,7 +56,7 @@ sub preprocess (@) {
$$text_ref=&Encode::decode_utf8($$text_ref); $$text_ref=&Encode::decode_utf8($$text_ref);
chomp $$text_ref; chomp $$text_ref;
}, },
filename => srcfile($template_file), filename => $template_file,
die_on_bad_params => 0, die_on_bad_params => 0,
no_includes => 1, no_includes => 1,
blind_cache => 1, blind_cache => 1,

2
debian/changelog vendored
View File

@ -26,6 +26,8 @@ ikiwiki (3.20100324) UNRELEASED; urgency=low
* page.tmpl: Add Cache-Control must-revalidate to ensure that users * page.tmpl: Add Cache-Control must-revalidate to ensure that users
(especially of Firefox) see fresh page content. (especially of Firefox) see fresh page content.
* htmlscrubber: Allow colons in urls after '?' * htmlscrubber: Allow colons in urls after '?'
* template: Search for templates in the templatedir, if they are not
found as pages in the wiki.
-- Joey Hess <joeyh@debian.org> Sat, 13 Mar 2010 14:48:10 -0500 -- Joey Hess <joeyh@debian.org> Sat, 13 Mar 2010 14:48:10 -0500

View File

@ -43,6 +43,12 @@ page will provide a link that can be used to create the template. The template
is a regular wiki page, located in the `templates/` subdirectory inside is a regular wiki page, located in the `templates/` subdirectory inside
the source directory of the wiki. the source directory of the wiki.
(Alternatively, templates can be stored in a directory outside the wiki,
as files with the extension ".tmpl".
By default, these are searched for in `/usr/share/ikiwiki/templates`;
the `templatedir` setting can be used to make another directory be searched
first.)
The template uses the syntax used by the [[!cpan HTML::Template]] perl The template uses the syntax used by the [[!cpan HTML::Template]] perl
module, which allows for some fairly complex things to be done. Consult its module, which allows for some fairly complex things to be done. Consult its
documentation for the full syntax, but all you really need to know are a documentation for the full syntax, but all you really need to know are a

View File

@ -6,3 +6,5 @@ source, but also looks in the system templates directory (the one with
invoked via `\[[!template]]`, but don't have to "work" as wiki pages in their invoked via `\[[!template]]`, but don't have to "work" as wiki pages in their
own right. I think the normal [[plugins/template]] plugin could benefit from own right. I think the normal [[plugins/template]] plugin could benefit from
this functionality. this functionality.
[[done]] --[[Joey]]

View File

@ -5,7 +5,8 @@ to learn.
The aim is to keep almost all html out of ikiwiki and in the templates. The aim is to keep almost all html out of ikiwiki and in the templates.
It ships with some basic templates which can be customised. These are It ships with some basic templates which can be customised. These are
located in /usr/share/ikiwiki/templates by default. located in `/usr/share/ikiwiki/templates` by default; the `templatedir`
setting can be used to make another directory be searched first.
* `page.tmpl` - Used for displaying all regular wiki pages. * `page.tmpl` - Used for displaying all regular wiki pages.
* `misc.tmpl` - Generic template used for any page that doesn't * `misc.tmpl` - Generic template used for any page that doesn't
@ -43,7 +44,8 @@ The [[plugins/pagetemplate]] plugin can allow individual pages to use a
different template than `page.tmpl`. different template than `page.tmpl`.
The [[plugins/template]] plugin also uses templates, though those The [[plugins/template]] plugin also uses templates, though those
[[templates]] are stored in the wiki and inserted into pages. [[templates]] are typically stored as pages in the wiki, and are inserted
into pages.
The [[plugins/edittemplate]] plugin is used to make new pages default to The [[plugins/edittemplate]] plugin is used to make new pages default to
containing text from a template, which can be filled as out the page is containing text from a template, which can be filled as out the page is