DokuWiki

It's better when it's simple

User Tools

Site Tools


namespace_templates

Namespace Templates

Dokuwiki supports scaffolding. 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 file exists and it shows it within the editor window. The templates therefore are .txt files and should contain wiki markup.

Template files

Two kinds of template files can be used:

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

If both (inherited and normal) templates are present in a namespace, the normal one is used, when a new page is created. Note: Any changes to your template files will only take effect for new pages you create in that namespace.

One way to create the template file is to:

  1. use the wiki to save a page with the content that you want to use as a template into the appropriate namespace
  2. use FTP or WebDAV to rename it as _template.txt

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
@CURNS@ last part of the namespace of the page
@!CURNS@ same as above but with the first character uppercased
@!!CURNS@ same as above but with the first character of all words uppercased
@!CURNS!@ same as above but with all characters uppercased
@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
%% a literal % character appears in your template

Still editing templates via wiki

You can't edit the _template.txt through DokuWiki (only someone who can edit the files inside the filesystem folders (usually an administrator using FTP or WebDAV) can modify these files). There are three ways to accomplish this, though:

  • the easiest is using the TemplatePagename plugin which let you change the default templatenames _template and __template into another name. E.g. c_template and i_template. These files are considered normal editable wikipages because they don't start with an underscore.
  • or by setting up through symbolic links

NOTE: This section contains instructions for use on a Linux server and will not work on a Windows system.

This way, you can store your templates in a special namespace, and make symlinks for DokuWiki to find them. You can also choose to make a specific template non-editable by removing its particular 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 editable.
  3. Follow the instructions given above, but make _template.txt a hard link 1) to the correct page under your templates namespace. You now have a template that can be modified easily via the wiki interface.

Another way is to create symlinks in the folder itself. Thus you create a template.txt which is a symbolic link to the _template.txt, in it's own namespace.

cd /var/www/html/dokuwiki/data/pages/namespace/something
ln -s _template.txt template.txt

For these softlinks to work, you might need the FollowSymLinks option set for this directory in your webserver's configuration.

NOTE: This section contains instructions for use on a Windows server and will not work on a Linux system.

Open up command prompt (cmd.exe) on the server, and browse to the location you with there to be a template. Use the MKLINK command to create a symbolic link.

cd c:\inetpub\wiki\data\pages\namespace\something
mklink template.txt _template.txt

Plugins

Additional template features are implemented by plugins.

  • TemplatePagename Plugin can change the names of _template and __template in your choice via configuration manager. Has as defaults respectively c_template and i_template. This plugin will let you choose normal wiki pages as template so that they are editable via the wiki interface.
  • TemplateByName Plugin extends available templates with
    • ~yourpagename.txt for the page named yourpagename in the current namespace
    • ~yournamespace.txt for all pages in the subnamespace named yournamespace
    • and variants for deeper namespaces too and some other templates e.g. for start pages.

All these plugins are only editable via the file system.

  • NewPageTemplate Plugin adds a URL parameter that defines which existing page from the wiki is loaded as the template. Every page allowed by ACL is available.
  • Snippets Plugin adds a button to the editor toolbar which allows to easily insert templates while editing a page. The shown templates needs to be list on one page, default snippets.
  • Headerfooter Plugin adds header text or footer text to pages only when they are displayed.

Troubleshooting

Problem: An unexpected error occurs “no timestamp” when server (Linux Ubuntu) cannot write the directory /dokuwiki/data/pages/namespace. This might happen, when the namespace directory is created by the admin as <root> in order to put the namespace template file in /dokuwiki/data/pages/namespace/, before creating the first page.

Solution: Create a dummy page, like so: yourserver/doku.php?id=namespace:dummy&do=edit. This allows DokuWiki to create the namespace directory under own control and assures full write permissions for DokuWiki on the created directory.

1)
soft links seem not to work, but see the note about FollowSymLinks below
namespace_templates.txt · Last modified: 2023-08-24 11:25 by 212.201.117.6

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