Translations of this page?:

Namespace Templates

Sometimes you might want to have every page in a certain namespace 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 a template files exists and it shows it within the editor window. The templates therefore are .txt files and should contain wiki markup.

Template files

Two kind of template files can be used :

  • _template.txt which is used in the current namespace.
  • and __template.txt (two leading underscores) which just work as the normal _template.txt files apart from the fact it is used in all namespaces below as well (They are inherited).

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.

Syntax

The content of the file is just standard wiki markup.

Replacement patterns

Inside of the file, you may also use some replacement patterns to make the template a little more dynamic.

@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 develonly
@!!PAGE@ same as above but with the first character of all words uppercased develonly
@!PAGE!@ same as above but with all characters uppercased develonly
@FILE@ page name (ID without namespace, underscores kept as is) develonly
@!FILE@ same as above but with the first character uppercased develonly
@!FILE!@ same as above but with all characters uppercased develonly
@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

In addition you may also use any strftime placeholder to insert the time of page creation in any format you like. If you want to use a literal % character in your template you need to double it.

Editing templates

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. There are two tricks to accomplish this, though: one involving setting up symbolic links once, and one involving a code change.

Editable templates through symbolic links

This way, you can store your templates in a special namespace. By making a symlink to them you can use the template. You can also choose to make a template non-editable by not using a symlink.

  1. Create a namespace called “templates”, or something similar.
  2. In this namespace, create a page for each Namespace Template that you wish to be available.
  3. Follow the instructions given in the manual, but make _template.txt a symlink to the correct page under your templates namespace. You now have a template that can be modified easily via the wiki interface.

Editable templates for all users

This way, all your templates will be editable by anybody with write access.

  1. Change the default template name to “template.txt” at around line 623 inc/common.php.
  2. Now any user with write access in the namespace can create a page called “template” in that namespace which will serve as the template.
 
namespace_templates.txt · Last modified: 2008/10/26 08:53 by andi
 

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate