名前空間テンプレート

Sometimes you might want that every page in a certain namespace is based on a common skeleton. For example, in the address namespace you could have an already prepared table, which only needs to be filled with data. This can be easily achieved with so called “namespace templates”. When a page is created, DokuWiki looks up whether there is a file _template.txt in that namespace and copies it into the edit field for the new page.

You can't edit the _template.txt through DokuWiki – only someone who can edit the files inside the DokuWiki folders (usually an administrator using FTP or WebDAV) can.1)2) One way to create the template file is to

  • use the wiki to save a page with the content that you want to use as a template into the appropriate namespace
  • use FTP or WebDAV to make a copy of it in the same folder and rename it, then
  • use the wiki to delete the original page.

There are a few replacement patterns you can use:

@ID@ full ID of the page
@NS@ namespace of the page
@PAGE@ page name (ID without namespace and underscores replaced by spaces)
@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

← Return to 日本語マニュアル

1)
You can allow the editing in the wiki to admins with the following hack: Open inc/pageutils.php and look for the function cleanID(). At the beginning, introduce global $INFO
  global $INFO;
then replace about line 98 (the one with trim() ) with
  $id = ($INFO['perm'] == 255 ? trim($id,':.-') : trim($id,':._-'));
Now you should be able to edit a namespace template with the URL doku.php?id=_template&do=edit. Note: This does not appear to work for templates in any namespace other than the root namespace.
2)
If you want to allow anybody to edit the template you can change its name to “template.txt” at around line 524 inc/common.php. Then any user with write access in the namespace can create a page called “template” in that namespace which will serve as the template.