It's better when it's simple

User Tools

Site Tools


newpagetemplate Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" yes
  • 2016-06-26 "Elenor Of Tsort" yes
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" yes

plugin Loads predefined page content from a given template

Last updated on

Tagged with button, editing, template


This plugin loads into the edit window a template specified in the $_REQUEST “newpagetemplate” parameter. 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.

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.


If a new page is created with the URL:


then the :pagetemplates:yourtemplate page is pasted into the edit window. If the “standardreplace” configuration option is true, then the substitutions noted below are performed. If the “userreplace” configuration option is true, then you can also replace @HI@ with Howdy!, as this substitution was passed in newpagevars. 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@

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' marcro.

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:


You may find with use that there are others.


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
@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
standardreplaceReplace standard macros as listed above in substitutions
prettytitles Replace underscores with spaces in the following standard macros @!PAGE@, @!!PAGE@,@!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


Change Log


Could anybody provide me a simple description or example for the usage of the plugin in combination with 'addnewpage'?
Thanks, Matt
See the openas plugin

When accessing a non-existing page you're provided with a text:
This topic does not exist yet
You've followed a link to a topic that doesn't exist yet. If permissions allow, you may create it by using the Create this page button

It would be nice to add text where the user can choose from different templates, your plugin would then provide the URL to match the name of the page and the user has choice from different templates. Or am I missing something here ?
I have a same question. Can anybody explain me how to use a new page template when adding a page. I am new to PHP and don't know anything. Your help is highly appreciated.
Thanks, George

This plugin helped me quickly setup template pages for my students to work on, today. Thanks! The only inconvenience was that I had to create a unique link for each student to follow. For example:

  * [[:courses:isci422:projects:Ima Student:start?do=edit&rev=&newpagetemplate=:courses:isci422:projects:template|]]
  * [[:courses:isci422:projects:Anutha Student:start?do=edit&rev=&newpagetemplate=:courses:isci422:projects:template|]]
  * ...

It would have been even better if I could have created a single link with a substitution in the linked namespace, like:


I don't know if it's feasible but it sure would be cool :-)Rik BlokRik Blok

2011/11/08 05:42

The problem here would be where to get the substitutions from. Somewhere there would have to be a list of names for @NAME@ and some way to identify which name to use for the substitution.
I tried to use your conception and for substitutes was used bureaucracy+pagemod plugins. I have noticed some drawback. After creating link on new page it is possible just to open for editing it. For end users it is not suitable to delete this part of code (start?do=edit&rev=&newpagetemplate=:courses:isci422:projects:template)
I may not have explained myself clearly. I'd like substitutions like @NAME@ also to work in urls created by newpagetemplate. For example, if the user 'Ima User' clicks the link

then a new page is created for editing at :namespace:Ima User:start. Does that make sense? Thanks. — Rik BlokRik Blok

2013/01/25 20:31

There are several problems with this. First, with a url like this, the server couldn't know where to direct the request, since the address is initially incomplete. The request is sent out before @Name@ can be filled in. But what I missed in my earlier response is that these would be illegal names. And Dokuwiki when it parses the file, will remove the @-signs, and so you will end up with :namespace:NAME:start.

How does the interaction with existing namespacetemplates work?

There should be no interaction. The templates for newpagetemplate are regular Dokuwiki pages, not Dokuwiki templates. That is, they are named my_template.txt and not __my_template.txt or _my_template.txt. You should probably keep them in a directory which is protected by ACL from access by unauthorized users.
Thank you!

I am trying to run newpagetemplate together with addnewpage. Not being fluent in php and programming, I don't know how to generate a patched version of the addnewpage/syntax.php. I tried to patch it manually. But as soon as I include this patched syntax.php each request to my portable server to load my dokuwiki into the firefox window fails. How to do it properly? The link with the patched code in the addnewpage-discussion does not lead to such a file anymore.

See the openas Plugin. This will let you use the newpagetemplate plugin to create a Dokuwiki internal link that opens a new page with your template substitutions.
I have a wikipage named “materialdata”. I want to provide a template for all new pages created by links from that page (or alternatively by an addnewpage-dialogue on that page - in that case the template would include the tag “material”, so that the new pages will be displayed on the materials page by {{topic>material}} ). My problem is: The names of the new pages are given by the users. I would like to keep the interaction as simple as possible as most users in our wiki tend to use a wysiwyg editor. How can I use the openas-Plugin to provide a template for a page named by the user?
You can't. The simplest solution would be to create a standard Dokuwiki template with double underscores, so that it controls all subdirectories beneath it. Then with the addnewpage plugin, let your users open new pages in the namespace controlled by that template. With addnewpage, you can do this:

Then your users will get a text box in which to enter the name of a page which will open in my_namespace. If you have a template in my_namespace, then when the page is created, it will use that template. If you use the double underscore version of the template then the user can a page in a subdirectory of that namespace and still have the template operative.

Sadly we tried to avoid namespaces as we wanted to make linking (across subjects, even to the materialdata pages) as simple as possible for the users. Does the combination of addnewpage and newpagetemplate not work?
Then use this:

That will link to a page in the root directory. Then you can put your template in the root.
Both the addnewpage and the newpagetemplate plugins do the same thing, insofar as they both link to a new page. The difference is that newpagetemplate implements a template in the url.
If you have further questions raise them on the forum. You might find solutions there.

Thank you very much!
plugin/newpagetemplate.txt · Last modified: 2017-03-21 01:25 by turnermm