From 59ba938822ba0752e8d97e769c0d14f2eb0bbeb3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 2 Apr 2010 16:54:06 -0400 Subject: [PATCH] template: Search for templates in the templatedir, if they are not found as pages in the wiki. --- IkiWiki/Plugin/template.pm | 10 ++++++++-- debian/changelog | 2 ++ doc/templates.mdwn | 6 ++++++ doc/todo/user-defined_templates_outside_the_wiki.mdwn | 2 ++ doc/wikitemplates.mdwn | 6 ++++-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm index 3e024c5f8..36282055a 100644 --- a/IkiWiki/Plugin/template.pm +++ b/IkiWiki/Plugin/template.pm @@ -37,7 +37,13 @@ sub preprocess (@) { my $template_page="templates/$params{id}"; 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"), htmllink($params{page}, $params{destpage}, "/".$template_page)) unless defined $template_file; @@ -50,7 +56,7 @@ sub preprocess (@) { $$text_ref=&Encode::decode_utf8($$text_ref); chomp $$text_ref; }, - filename => srcfile($template_file), + filename => $template_file, die_on_bad_params => 0, no_includes => 1, blind_cache => 1, diff --git a/debian/changelog b/debian/changelog index adf0dfed6..362ba54ab 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,6 +26,8 @@ ikiwiki (3.20100324) UNRELEASED; urgency=low * page.tmpl: Add Cache-Control must-revalidate to ensure that users (especially of Firefox) see fresh page content. * 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 Sat, 13 Mar 2010 14:48:10 -0500 diff --git a/doc/templates.mdwn b/doc/templates.mdwn index eff0e15e9..07531ae98 100644 --- a/doc/templates.mdwn +++ b/doc/templates.mdwn @@ -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 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 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 diff --git a/doc/todo/user-defined_templates_outside_the_wiki.mdwn b/doc/todo/user-defined_templates_outside_the_wiki.mdwn index 880ad6493..1d72aa6a7 100644 --- a/doc/todo/user-defined_templates_outside_the_wiki.mdwn +++ b/doc/todo/user-defined_templates_outside_the_wiki.mdwn @@ -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 own right. I think the normal [[plugins/template]] plugin could benefit from this functionality. + +[[done]] --[[Joey]] diff --git a/doc/wikitemplates.mdwn b/doc/wikitemplates.mdwn index 6c0480cea..6e5a7261d 100644 --- a/doc/wikitemplates.mdwn +++ b/doc/wikitemplates.mdwn @@ -5,7 +5,8 @@ to learn. 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 -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. * `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`. 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 containing text from a template, which can be filled as out the page is -- 2.26.2