PkTemplate

Summary: Easily create multiple pages from a user-supplied template
Version: 20170111
Status: stable
Maintainer: Peter Kay
License: GPL3+
Categories: Editing Templates
Users: (view? / edit)
Discussion: PkTemplate-Talk?

Allow quickly creating multiple pages from a user-supplied template.

Description

PkTemplate allows a user to write a template using wiki markup and then rapidly create new pages based on that template.

Installation

As usual,

  • Copy PkTemplate.phpΔ to your pmwiki/cookbook directory
  • Add the following line to local/config.php:
    include_once("$FarmD/cookbook/PkTemplate.php");

Usage

Creating a template

Create a page you'd like to use as a template. The page may contain non-template information; the template part starts with the markup:

  (:PkTemplate:)

Anything after that is part of the template.

Create fields that a user can populate with data using the markup (:pktvar variablename A description of the variable:)

  • pktvar = PK Template Variable
  • don't use symbols in names
  • limited markup for descriptions is ok, but nothing with :)

If you use the same variable more than once in the page, you may omit the description: (:pktvar variablename:) (It will be ignored if you do give additional descriptions.)

Create blocks of text a user can populate with the Markup:

(:pkttext textblockname Description of what multi-line text goes here:)

Save the page and then you will be presented with a form to create new pages based on your template.

Filling out the form to create new pages

  • New page name: New page names may contain spaces
    • Creates a page Main.NewPageNamesMayContainSpaces
  • New page name: May Use Group. Name For Convenience
    • Creates MayUseGroup.NameForConvenience - ignores the "Group" field
  • If "Add link to created page" is checked, a link to the newly created page will be added to the top of the template page
    • This is useful to not lose pages.
    • (Admin may change whether this is checked by default by specifying $PkTemplate['addLinkByDefault']=false; in config.php)

What it looks like

If the template looks like this:

* [[Main.Enki-Addu | Enki-Addu]] * [[Main.Micro | Micro]] (links to previously created pages) (:pktemplate:) (:pktvar catname The name of the cat:) likes to (:pktvar catpasttime What does the cat like to do?:). (:pktvar catpronoun What pronoun does the cat use?:) is very soft.

(:pktvar catpronoun:) says:

(:pkttext meowmeow What the cat has to say to us ''humans'':)


A user might fill out the form like this:

Group:
New page name:
Author:
 
The name of the cat
What does the cat like to do?
What pronoun does the cat use?
What the cat has to say to us humans

And would create the page Main.LunarLander with contents:

Luna likes to Watch squirrels out the window. She is very soft.

She says:

Meow meow MROW 'MORWWW!'

Notes

  • There is no real difference between (:pktvar ...:) and (:pkttext ...:). Both accept Markup and both may be multiline if a user is determined enough.
  • Capitalization in the "template" markup is not important. (:PkTemplate:) and (:pktemplate:) both work. Currently, both (:pktvar ...:) and (:PKTVAR ...:) work, but that is not guaranteed in the future: use lowercase "pktvar/pkttext" by preference.
  • Don't (:include TemplatePages:) - the behavior is undefined. If you really need this, let me know, I might be able to provide an update.
  • PkTemplate will not overwrite pages that already exist.

Configuration

Admins may easily change a few behaviours:

  $PkTemplate['addLinkByDefault']=false;     // checkbox to add link to new pages is not checked
  SDV($HandleAuth['pkdotemplate'], 'admin'); // change permissions to admin(read/etc)
  include_once("$FarmD/cookbook/PkTemplate.php");

Change log / Release notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

2017.04.18 Release

  1. Markup text displayed at bottom of page now honors $ROEPatterns, so user sees what they would see if they edited the page
  2. PkTemplate markup now runs "<_begin" so that (almost all) markup will actually be included in the template, including [=comments=], etc.

See also

Contributors

Comments

See discussion at PkTemplate-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.