DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:newpagetemplate

newpagetemplate Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" yes
  • 2023-04-04 "Jack Jackrum" yes
  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" yes

plugin Loads predefined page content from a given template

Last updated on
2023-10-19
Provides
Syntax, CLI
Repository
Source

Similar to copypage, templatepagename

Tagged with button, editing, post, template, url

Needed for openas

Description

This plugin loads into the edit window a template specified in the newpagetemplate parameter of the $_REQUEST global. Effectively, this means that you can invoke a template, similar to the namespace template pages, either in the URL or in a POST form coded to create a new page. In simple terms, you can create a page in your dokuwiki and then use that page as a template for new pages. The plugin has been extensively modified and integrated into the openas plugin by Myron Turner.

The openas plugin and the addnewpage plugin provide techniques which support the newpagetemplate plugin. The openas plugin includes a simple method of creating a form designed for use with the newpagetemplate plugin, making it possible for each user to assign unique values to the template's variables.

Usage

If a new page is created with the URL:

doku.php?id=:mynewpage&do=edit&rev=&newpagetemplate=:pagetemplates:yourtemplate&newpagevars=@HI@,Howdy!;@NAME@,Joe

then the :pagetemplates:yourtemplate template is pasted into the edit window with all macro substitutions completed. If the standardreplace configuration option is true, then the substitutions detailed below are made. If the userreplace configuration option is true, then you can pass in additional macros and their substitutions using the newpagevars option, as illustrated in above example url. In that example, wherever the template has @HI@, it will be replaced with Howdy! The format for newpagevars is:

 newpagevars=key,value;key2,value2;key3,value3;

See configuration_options and substitutions for a description of the standard and user replacements.

Example of syntax for a template page

If you create a template page yourtemplate with this markup in :pagetemplates:

This page is: @ID@
  
@HI@ @NAME@

And if you paste the above URL into your browser's location bar, you will get a page in your browser that looks something like this:

This page is: mynewpage
 
Howdy! Joe

@ID@ is one of the 'standardreplace' macros and @HI@ is a 'userreplace' macro.

Is it possible to use standard wiki-link syntax for this? For eg. like:

[[:mynewpage?do=edit&rev=&newpagetemplate=:pagetemplates:homepagetemplate&newpagevars=@HI@,Howdy!|New page with template]]  

Yes, you can do this. But you will have to substitute some url-encoded characters. In particular, the comma must be represented as %2c. So this would give you:

&newpagevars=@HI@%2CHowdy

You may find with use that there are others.

Substitutions

As with the _template.txt namespace templates, the following variables are replaced in your template.

@ID@ full ID of the page
@NS@ namespace of the page
@PAGE@ page name (ID without namespace and underscores replaced by spaces)
@!PAGE@ same as above but with the first character uppercased
@!!PAGE@ same as above but with the first character of all words uppercased
@!PAGE!@ same as above but with all characters uppercased
@FILE@ page name (ID without namespace, underscores kept as is)
@!FILE@ same as above but with the first character uppercased
@!FILE!@ same as above but with all characters uppercased
@USER@ ID of user who is creating the page
@NAME@ name of user who is creating the page
@MAIL@ mail address of user who is creating the page
@DATE@ date and time when edit session started
%a %d-%m-%y etc. e.g. Thu 06-12-12. strftime placeholders are replaced by page creation time

Configuration Options

userreplace Replace user defined macros as explained above in usage
standardreplace Replace standard macros as listed above in substitutions
prettytitles Replace underscores with spaces in the following standard macros @!PAGE@, @!!PAGE@,@!PAGE!@
skip_unset_macros Remove macros which have no substitution values, so that they don't appear in the newly created page.

The prettytitles patch was contributed by Matthias Bannach.

Version History

This plugin was originally written by Jason Grout. It was later modified by: Sergio (1 Apr 2007), an unidentified author, and Niko Paltzer (15 Jan 2010). The original version was not compatible with current Dokuwiki distributions (post-2010-03-10). The current version of newpagetemplate supports all current distributions of Dokuwiki and is backwardly compatible with distributions going back to 2006.

The original version of newpagetemplate has security concerns which have been addressed in the current distribution. In the earlier version, ACL is not checked before the template page is accessed, which means that anyone with access to the wiki can access the template page. A user with enough rights in one part of the wiki might access any page in the whole wiki. Moreover, user input inserted with the userreplace option was not sanitized, making it possible to inject code with malicious intentions.

If you wish to use the original version it is available from github

Alternate Interfaces

openas

There is an alternate interface in the openas plugin which enables the creation of forms that pass the data to newpagetemplate. See the expanded syntax section.

CLI

There is a module of newpagetempate that implements DokuWiki's CLI protocol. This enables the plugin to be run from the command line and to process multiple files and templates from one command. In addition to command-line access it also provides an admin plugin to facilitate working with the command line features. See newpagetemplate:cmdline for further details and the download link.

Bugs

Discussion

See discussion page for some early discussion topics

Change Log

plugin/newpagetemplate.txt · Last modified: 2024-03-08 09:19 by dregad

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki