TemplateMarkupTricks

Summary: Various ways of using templates to facilitate the creation of new pages (using standard PmWiki markup)
Version: 2014-02-20
Maintainer: StefCT
Licence: GPL
Users: (view? / edit)

Questions answered by this recipe

I want to use templates to help wiki editors create new pages. How can I achieve this without installing any additional scripts or making changes to config.php?

Description

This recipe is a collection of ideas of what can be achieved with templates, the template=URL parameter and standard PmWiki markup.

Installation

In a standard (recent) PmWiki installation the markup examples listed below should work out of the box using copy and paste.

Chose an existing page from the current group as a template:

(:if auth edit {$Group}.ImaginaryNewPage:)
(:input form "{$PageUrl}" get:)
(:input hidden action edit:)'''New page:''' \
(:input text pagename "{$Group}.NewPage" size=25:) \
'''based on template:''' \
(:pagelist fmt=#tpldropdownlist group={$Group} list=normal wrap=inline:) \
(:input submit value="Create":)(:input end:)
(:ifend:)

(:if false:)
[[#tpldropdownlist]]
(:input select name=template value={=$FullName} label="{=$Name}":)
[[#tpldropdownlistend]]
(:ifend:)

New page: based on template:

Note: If you'd like to exclude certain pages from your list of templates, please take a look at pagelists documentation about how to customize the (:pagelist:) directive from above.

List all templates from a particular group:

If you prefer to store all your templates in a particular group, e.g. Templates, simply replace the first and the last incident of {$Group} with Templates in the markup from the section above:

(:if auth edit Templates.ImaginaryNewPage:)
(:input form "{$PageUrl}" get:)
(:input hidden action edit:)'''New page:''' \
(:input text pagename "{$Group}.NewPage" size=25:) \
'''based on template:''' \
(:pagelist fmt=#tpldropdownlist group=Templates list=normal wrap=inline:) \
(:input submit value="Create":)(:input end:)
(:ifend:)

(:if false:)
[[#tpldropdownlist]]
(:input select name=template value={=$FullName} label="{=$Name}":)
[[#tpldropdownlistend]]
(:ifend:)

New page: based on template:

Note: If you'd like to offer an empty/default template as well, simply create an empty page named something like "None" or "Default" in your Templates group.

Allow editors to chose from a list of pre-filled templates:

For every template, create an entry like this: (:input select name=template value=Group.TemplateName label="Name of Template":)

Example: (:input select name=template value=Cookbook.TemplateMarkupTricks label="TemplateMarkupTricks":)

... and insert it into the following markup after (:comment list your templates here:):

(:if auth edit {$Group}.ImaginaryNewPage:)
(:input form "{$PageUrl}" get:)
(:input hidden action edit:)
'''New page:''' (:input text pagename "{$Group}.NewPage" size=25:) \
'''based on template:''' \
(:comment list your templates here:)
(:input select name=template value=Cookbook.TemplateMarkupTricks label="TemplateMarkupTricks":)
(:input select name=template value=none label="none":)
(:comment template list end:)
(:input submit value="Create":)(:input end:)
(:ifend:)

New page: based on template:

Duplicate existing pages using templates:

Initially suggested here: EditTemplates-Talk

Put the following code in *.GroupFooter:

(:if auth edit {$Group}.ImaginaryNewPage:)
(:input form "{$PageUrl}" get:)
(:input hidden action edit:)
(:input hidden template {*$FullName}:)
New page based on current: (:input text pagename "{$Group}.NewPage" size=32:)
(:input submit value="Create":)
(:input end:)
(:ifend:)

New page based on current:

In your SideBar, use instead:

(:if auth edit {*$Group}.ImaginaryNewPage:)
(:input form "{$PageUrl}" get:)
(:input hidden action edit:)
(:input hidden template {*$FullName}:)
New page based on current: (:input text pagename "{*$Group}.NewPage" size=32:)
(:input submit value="Create":)
(:input end:)
(:ifend:)

New page based on current:

Create new template based page with random name:

Notes:

  • please change Cookbook.Template to group and name of your actual template
  • the page name will be the current timestamp combined with a random number between 1 and 10000
  • for creating multiple new pages the page containing the "new page" link needs to be reloaded each time in order to generate a fresh (random) page name
  • useful for "database-style" applications with page text variables and page lists; the template can contain the names of page text variables as "database fields"
[[Create new page in group "{$Group}" based on template -> {(ftime fmt="%s")}{(rand 1 10000)}\
?action=edit&template=Cookbook.Template]]

Create new page in group "Cookbook" based on template


Change log / Release notes

  • 2014-02-20: initial release
  • 2014-03-20: added note regarding template based pages with random names

See also

Contributors

Comments

See discussion at TemplateMarkupTricks-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.