--- /dev/null
+#!/usr/bin/perl
+package IkiWiki::Plugin::edittemplate;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+sub import { #{{{
+ hook(type => "needsbuild", id => "edittemplate",
+ call => \&needsbuild);
+ hook(type => "preprocess", id => "edittemplate",
+ call => \&preprocess);
+ hook(type => "formbuilder_setup", id => "edittemplate",
+ call => \&formbuilder_setup);
+} #}}}
+
+sub needsbuild (@) { #{{{
+ my $needsbuild=shift;
+
+ foreach my $page (keys %pagestate) {
+ if (exists $pagestate{$page}{edittemplate}) {
+ if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
+ # remove state, it will be re-added
+ # if the preprocessor directive is still
+ # there during the rebuild
+ delete $pagestate{$page}{edittemplate};
+ }
+ }
+ }
+} #}}}
+
+sub preprocess (@) { #{{{
+ my %params=@_;
+
+ return "" if $params{page} ne $params{destpage};
+
+ if (! exists $params{template} || ! length($params{template})) {
+ return return "[[meta ".gettext("template not specified")."]]";
+ }
+ if (! exists $params{match} || ! length($params{match})) {
+ return return "[[meta ".gettext("match not specified")."]]";
+ }
+
+ $pagestate{$params{page}}{edittemplate}{$params{match}}=$params{template};
+
+ return sprintf(gettext("edittemplate %s registered for %s"),
+ $params{template}, $params{match});
+} # }}}
+
+sub formbuilder_setup { #{{{
+ my %params=@_;
+ my $form=$params{form};
+ my $page=$form->field("page");
+
+ return if $form->title ne "editpage"
+ || $form->field("do") ne "create";
+
+ $form->field(name => "editcontent", value => "hi mom!");
+} #}}}
+
+1
--- /dev/null
+[[template id=plugin name=edittemplate author="[[Joey]]"]]
+[[tag type/useful]]
+
+This plugin allows registering template pages, that provide default
+content for new pages created using the web frontend. To register a
+template, insert a [[PreprocessorDirective]] on some other page.
+
+ \[[edittemplate template="bugtemplate" match="bugs/*"]]
+
+In the above example, the page named "bugtemplate" is registered as a
+template to be used when any page named "bugs/*" is created.
+
+[[template id=note text="""
+Note: It's generally not a good idea to put the `edittemplate` directive in
+the template page itself, since the directive would then be included as
+part of the template on new pages, which would then in turn be registered
+as templates. If multiple pages are registered as templates for a new page,
+an arbitrary one is chosen, so that could get confusing.
+"""]]
+
+Often the template page contains a simple skeleton for a particular type of
+page. For the bug report pages in the above example, it might look
+something like:
+
+ Package:
+ Version:
+ Reproducible: y/n
+ Details:
+
+The template page can also contain [[cpan HTML::Template]] directives,
+similar to other ikiwiki [[templates]]. Currently only one variable is
+set: `<TMPL_VAR name>` is replaced with the name of the page being
+created.
provide a link that can be used to create the template. The template is a
regular wiki page, located in the `templates/` directory.
-The template uses the syntax used by the
-[cpan HTML::Template](http://search.cpan.org/search?mode=dist&query=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 few things:
+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
+few things:
* To insert the value of a variable, use `<TMPL_VAR variable>`.
* To make a block of text conditional on a variable being set use
will also only work when using web-editing, but the people using
rcs-editing (coining new terms, eh ;-)?) usually know what they're doing.
---[[tschwinge]]
\ No newline at end of file
+--[[tschwinge]]
+
+> [[done]] in the [[plugins/edittemplate]] plugin. --[[Joey]]
different template than `page.tmpl`.
The [[plugins/template]] plugin also uses templates, though those
-[[templates]] are stored in the wiki.
+[[templates]] are stored in the wiki and inserted into pages.
+
+The [[plugin/edittemplate]] plugin is used to make new pages default to
+containing text from a template, which can be filled as out the page is
+edited.