EditTemplatesMenu

Scaffolding
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, PHP55, PHP72
License: PD

Description

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.

Installation

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

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

You need to edit the "pages" via the wiki interface like you edit other pages, do not modify the raw "files" on the disk.

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:)
(:ifend:)

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

You need to edit the "pages" via the wiki interface like you edit other pages, do not modify the raw "files" on the disk.

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:

[[#linktemplates]]
(: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:)
[[#linktemplatesend]]

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

Notes

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

  • EditTemplates   Specify a wiki page or pages to use as a template when a new page is created.
  • NewPageBoxPlus   Adds customisable box plus button form for page creation
  • TemplateMarkupTricks   Various ways of using templates to facilitate the creation of new pages (using standard PmWiki markup)

Author

Recipe created and maintained by Petko.

Comments

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.