It's better when it's simple

User Tools

Site Tools


Pagespace Plugin

Compatible with DokuWiki


plugin Additional syntax to allow a relative link to a namespace based on the current page name

Last updated on

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with links, namespace


I love DokuWiki, and use it all the time both at work as a knowledge repository, and at home for my own thoughts and ideas. The one thing I found a little tiresome was typing in long internal links; so I love the idea of relative links. It makes it much easier to create clean clear namespace layouts.

At present you can create the following relative links (if I've understood correctly…!):

  • To the root namespace
[[:new link]]
  • To the parent namespace (back 2)
[[..:new link]]
  • Or to the current namespace (back 1)
[[.:new link]]

What I propose adding is a syntax to create a link to the pagespace, i.e. a namespace based on the current page name


Let's assume the current page name (top left in a standard DokuWiki installation) is as follows:


This means that the current namespace is plugin and the current page is pagespace

Using the following syntax:

[[@new link]]  or  [[@:new link]]

This link would be created:


And that's basically all there is to it!


if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
/** Creates a relative link to the current 'Pagespace'
	i.e. a namespace based on current page name (page ID))
 	To use:
 	If current page name is: [[root:parent:current_page]]
		then [[@:new page]] or [[@new page]]
 		would result in the following link:
    License: GPL
class syntax_plugin_pagespace extends DokuWiki_Syntax_Plugin {
	function getInfo() {
		return array('author' => 'Symon Bent',
	                 'email'  => 'symonbent [at] gmail [dot-com]',
	                 'name'   => 'pagespace',
	                 'desc'   => "New syntax to allow a relative link to a namespace based on current page name, e.g. [[@:new page]]",
	                 'url'    => '');
  	function getType() {
    	return 'substition';
	function getSort() {
	    return 239;
	function connectTo($mode) {
	function handle($match, $state, $pos, &$handler) {
	  	//Swaps the @ symbol for the current page ID
	  	global $ID;
		global $conf;
		$pagespace = $ID;
	  	$link = $match;
		//Ignore the start (root) namespace
		if ($pagespace == $conf['start']) {
			$pagespace = '';
		} else {
			$pagespace .= ':';
		// Only replace an initial @ symbol, not elsewhere in link
		$link = str_replace("[[@", "[[".$pagespace, $link);
                // Strip the opening and closing markup
                $link = substr($link, 2, -2);
                // Split title from URL
                $link = preg_split('/\|/u', $link, 2);
                if ( !isset($link[1]) ) {
                    $link[1] = NULL;
	        return $link;
	function render($mode, &$renderer, $data) {
		if ($mode == 'xhtml') {
			$renderer->internallink($data[0], $data[1]);
			return true;
		return false;


  • 2008-01-15: First release, warts and all!
  • 2008-02-08: Bug fix - plugin now adds nothing to root namespace, and fixed a little bug in render function


This is only my second plugin, the previous one has not been published (it was a adaption of the explain plugin which allowed the glossary to be a normal wiki page. I found it very useful…anybody interested?)

  • Yes! — hansbkk
Okay, I'll make it available sometime.—Symon 2011-11-22

I still have much to learn so any suggestions, improvements, and comments are most welcome. Thanks to all the rest of you for sharing so generously!

  • Does it work with pagemove? — onn
  • Does it work with recent versions of DW? — hansbkk

I really like the idea of using this as the “home page” for a namespace - with all implementations of hierarchical organisation, there's always the question “is the container just a container, or does it also have content?” IMO tools should let the user decide - give the rationale for a tag in the tag itself, let it be a glossary entry for example. Nice work, but please keep it up to date with the current stable release of DokuWiki and indicate such in the plugin page. . .

Time…wish I had more of it! I haven't used it in a while so I do not know if it works on the new release. I'll check though and provide a proper zip download once I get a moment.—Symon 2011-11-22

Kewl, and know what you mean, low priority. In thinking about this, triggered again by I'm thinking maybe it would be better to make /string2/$conf['start'].txt the “standard” place for an “about the namespace” page, or even /string1/string2/string2.txt, rather than /string1/string2.txt? Obviously you (used to?) do it the latter way, did you run into issues that made you change?

I just wanted to add that this plugin seems to be working fine on Release 2014-09-29d “Hrun” and is EXACTLY what I was looking for and will save me a lot of little mistakes. For those unsure how to install manually, I saved the code above to a file called syntax.php and placed it in a folder I created “namespace” in the “lib/plugins” folder on the server. I'm new to DokuWiki myself but it seems to be working like a champ! Cowboy 2015-05-01

plugin/pagespace.txt · Last modified: 2015-05-02 05:35 by

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