Recent Changes - Search:




Summary: Allow authors a choice among several pre-filled templates for new pages
Version: 20090328
Prerequisites: PmWiki 2.2.0
Status: Stable
Maintainer: Petko
Categories: Editing, Menus, Forms, CMS
License: PD


Allow authors a choice among several pre-filled templates before creating new pages.

PmWiki's edit templates offer a convenient and easy way to pre-populate newly created pages with some content. The feature is also called "scaffolding" and helps the building of the new page. A sample page structure ensures authors will not forget to add, for example, the page title or the required categories.

The feature, via the variable $EditTemplatesFmt, offers much flexibility, however any changes must be done by the wiki administrator.

This recipe shows a powerful way to use different edit templates, personalized and selected by the wiki authors. Links to non-existing pages will lead to a menu (where the author can select the type of page) instead of directly to the edit text area.

The recipe doesn't depend on external php scripts, it only relies on PmWiki's core features.


1. In your local (farm)config.php, add the following line :

 $LinkPageCreateFmt = 
   "<a class='createlinktext' rel='nofollow' href='\$LinkUrl'>\$LinkText</a>";

2. On your wiki, edit the page [[Site.PageNotFound]] and append the following :

(:if4 auth edit:)
(:if ! exists {*$Group}.RecentChanges:)
(:include $[{$SiteGroup}.NewGroupWarning]:)
(:if exists {*$Group}.EditTemplates:)

'''Local ({*$Group}) templates'''
(:pagelist fmt={$FullName}#linktemplates trail={*$Group}.EditTemplates:)

'''Site edit templates'''
(:pagelist fmt={$SiteGroup}.PageNotFound#linktemplates trail=EditTemplates.EditTemplates:)
(:if false:)
* [[{*$FullName}?action=edit&template={=$FullName} | {=$Namespaced}]]

3. Edit your page [[EditTemplates.EditTemplates]] to add something like :

* [[New Empty Page]]
* [[New Article]]
* [[New Project]]
* [[New Blog Entry]]
* [[New Gallery Page]]
* [[New Page Type 2]]
* [[New Page Type 3]]

These are links to your edit templates. In these pages of the group EditTemplates/ you will pre-fill the content for each type of page. For example, EditTemplates.NewEmptyPage may contain something like:

Enter your content here.

(:title :)
(:description :)

Authors can personalize the Edit Templates by adding them to the bulleted list (trail) in EditTemplates.EditTemplates. The template pages may be anywhere, not only in the EditTemplates group.

Authors can also create a special page Group.EditTemplates in any Group, with a similar trail of group templates. In that case, the local list will appear before the site-wide one.

See also the recipe NewGroupWarning, which informs authors when they are about to create pages in non-existing wiki groups. If the Site.NewGroupWarning page exists, the same warning will appear on the select-edit-template menu.

Drop-down menus

You can use a drop-down menu instead of a bulleted list of links in the Edit menu. Change the code between [[#linktemplates]] and [[#linktemplatesend]] in Site.PageNotFound to this:

(:template first:)
(:input form action={*$PageUrl}:)
(:input hidden action edit:)(:input hidden n {*$FullName}:)
(:template each:)
(:input select template "{=$FullName}" "{=$Titlespaced}":)
(:template last:)
(:input submit go Create:)
(:input end:)

Note that the link trail in EditTemplates.EditTemplates still uses bulleted list of links.


Create your template pages with meaningful names, because the names are the only information authors will see in the menu. (Description, title, summary and other attributes in the template are better left empty or the authors may be annoyed or forget to change/delete them.)

PmWiki 2.2.x is required for the nested conditionals, for the menu to appear only to users with edit privileges.

Release notes

  • 20090328 : initial release

See also


Recipe created and maintained by Petko.


See discussion at EditTemplatesMenu-Talk

User notes +1: 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.

Edit - History - Print - Recent Changes - Search
Page last modified on July 18, 2014, at 02:39 AM