1 The [[ikiwiki/directive/inline]] directive allows the creation of new pages.
2 It would be nice if it was possible to specify default text for the new post.
5 \[[!inline pages="blog/* and !*/Discussion" postform="yes" newposttemplate="blogtemplate.mdwn"]]
7 This would allow you to create a new blog post. When you hit the `Edit` button, the system presents
8 you with an edit form as normal, but rather than being empty, it has the text from `blogtemplate.mdwn`.
10 Inline below is a [[patch]] that implements this:
14 diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
15 index bb21ed2..10c985c 100644
16 --- a/IkiWiki/Plugin/editpage.pm
17 +++ b/IkiWiki/Plugin/editpage.pm
18 @@ -60,7 +60,7 @@ sub cgi_editpage ($$) { #{{{
22 - my @fields=qw(do rcsinfo subpage from page type editcontent comments);
23 + my @fields=qw(do rcsinfo subpage from page type editcontent comments templatepage);
24 my @buttons=("Save Page", "Preview", "Cancel");
25 eval q{use CGI::FormBuilder};
27 @@ -117,9 +117,20 @@ sub cgi_editpage ($$) { #{{{
30 $type=$form->param('type');
32 + my $defaultContent = "";
33 + my $templatepage = $form->param('templatepage');
34 + if ($templatepage && $pagesources{$templatepage}) {
35 + $defaultContent = readfile(IkiWiki::srcfile($pagesources{$templatepage}));
38 if (defined $type && length $type && $hooks{htmlize}{$type}) {
39 $type=possibly_foolish_untaint($type);
41 + elsif ($templatepage && $pagesources{$templatepage}) {
42 + # favor the type of the template page
43 + $type=pagetype($pagesources{$templatepage});
45 elsif (defined $from && exists $pagesources{$from}) {
46 # favor the type of linking page
47 $type=pagetype($pagesources{$from});
48 @@ -129,7 +140,7 @@ sub cgi_editpage ($$) { #{{{
49 if (! $form->submitted) {
50 $form->field(name => "rcsinfo", value => "", force => 1);
52 - $form->field(name => "editcontent", validate => '/.+/');
53 + $form->field(name => "editcontent", value => $defaultContent, force => 0, validate => '/.+/');
56 $form->field(name => "do", type => 'hidden');
57 diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
58 index 8efef3f..075d7d8 100644
59 --- a/IkiWiki/Plugin/inline.pm
60 +++ b/IkiWiki/Plugin/inline.pm
61 @@ -271,6 +271,7 @@ sub preprocess_inline (@) { #{{{
62 $rootpage=$params{page};
64 $formtemplate->param(rootpage => $rootpage);
65 + $formtemplate->param(templatepage => $params{newposttemplate}) if $params{newposttemplate};
66 $formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
67 $formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
68 if (exists $params{postformtext}) {
69 diff --git a/templates/blogpost.tmpl b/templates/blogpost.tmpl
70 index 7eeede6..5c8b34c 100644
71 --- a/templates/blogpost.tmpl
72 +++ b/templates/blogpost.tmpl
75 <input type="hidden" name="do" value="blog" />
76 <input type="hidden" name="from" value="<TMPL_VAR ROOTPAGE>" />
77 +<TMPL_IF NAME="TEMPLATEPAGE">
78 +<input type="hidden" name="templatepage" value="<TMPL_VAR TEMPLATEPAGE>" />
80 <input type="hidden" name="subpage" value="1" />
81 <TMPL_VAR POSTFORMTEXT>
82 <input name="title" size="40" />
86 Perhaps I'm misunderstanding something, but can't you use already existing
87 in-house means instead of this patch; use a procedure as I do in the Hurd wiki?
88 <http://www.bddebian.com/~wiki/config_edittemplate/> with one template:
89 <http://www.bddebian.com/~wiki/config_edittemplate/regular_page/>.
92 > You are entirely correct. I thought I'd seen it somewhere, but then couldn't
93 > find it when I came to use it. If the patch isn't applied (and I can see arguments
94 > on both sides of that debate), then at least a pointer to
95 > [[ikiwiki/directive/edittemplate]] should be added to [[ikiwiki/directive/inline]]
96 > (and I'd make that change myself, but the edit needs to happen in the underlay,
97 > not in the online docs). -- [[Will]]
99 >> Go ahead and make the edit, ikiwiki's source is arranged such that edits
100 >> on this wiki to files that form the underlay will affect the underlay.
101 >> (Clearly I won't be adding duplicate functionality.)
104 >>> Edit made. [[done]] -- [[Will]]