Translations of this page?:

Alternate Namespace Template File

A suggestion for a default Name Space Template for a new (none existing) Sub Name Space.

I suggest Name Space Template idea be extended to include an alternate template if the default “NS/_template.txt” file does not exits.

I suggest as a second default file name of ”NS/../__template.txt” be used. Note: there are two underscores in this name.

This would allow for a default template for a yet none existing Name Space below an established one.

Adding the following “ERB” line to “function pageTemplate” (about line 508) in dokuwiki/inc/common.php does the trick!

  $tpl = io_readFile(dirname(wikiFN($id)).'/_template.txt');
  if(!$tpl) $tpl = io_readFile(dirname(dirname(wikiFN($id))).'/__template.txt');  /* ERB 20050118*/
  $tpl = str_replace('@ID@',$id,$tpl);

Maybe the actual template file name should be changed, but it works for me.

Thanks, Eldon R. Brown

BTW: I need to learn how to put two underscores on a wiki page?

Enclose a string in %% signs to prevent it getting interpreted by the parser.
I agree with Eldon, this is an almost essential feature for corporate environments where the same format is used over and over again. – Jerry Schwartz jerry at gii.co.jp
Just looking through the discussions for something very similar to this, and came across your mod. Very helpful, thanks! I've enhanced it a little to fit our needs, basically that for any given namespace, use the template that is defined there, or (failing to find one), recurse up through all namespaces until one is found. Code is below:
  global $INFO;
/**
 * Added following to recurse through namespace heirarchy for template
 */
  $dir = dirname(wikiFN($id));
  $tpl = io_readFile($dir.'/_template.txt');
  if( !$tpl ) {
    for( $dir = dirname($dir); !$tpl && $dir != $conf['datadir'] && file_exists($dir); $dir = dirname($dir) ) {
      $tpl = io_readFile($dir.'/_template.txt');
    }
  }
/**
 * End additions
 */
  $tpl = str_replace('@ID@',$id,$tpl);

Todd Pare 2006-04-13

Todd, I also like what you have done here but the implementation can be simplified;
  global $INFO;
/**
 * Added following to recurse through namespace heirarchy for template
 */
  for( $tpl = '', $dir = dirname(wikiFN($id)); !$tpl && $dir != $conf['datadir']; $dir = dirname($dir) ) {
    $tpl = io_readFile($dir.'/_template.txt');
  }
/**
 * End additions
 */
  $tpl = str_replace('@ID@',$id,$tpl);


Two changes, first the initialisation of the loop invariants is done in the for loop. The second is the check for the existence of the directory is removed which allows recursing over nonexisting namespaces such as when the first subpage is added to a new namespace i.e. creating top:new_ns:new_page before top:new_ns exists. – Alan 2007-07-19

Default Namespace Template + Page Specific Template in Namespace

Jason Byrne 2006-11-14

I like what Todd did above, but I had a slightly different need. This works as above, but allows you to specify templates for a specific file name in the namespace. Say the file is called mypage it will first look for a template file called _mypage_template.txt and then if that is not found it will look for the default for that namespace in _template.txt

This was very important to me because of some other hacks I have applied where my namespaces have index files defined. I wanted if someone was creating an index file for it to look one way, but if it was any other file to look another so I have two templates _index_template.txt and _template.txt

 
$pagearray = explode(":", $id);
$page = $pagearray[count($pagearray) - 1];
 
$dir = dirname(wikiFN($id));
$tpl = io_readFile($dir.'/_'.$page.'_template.txt');
if(!$tpl) $tpl = io_readFile($dir.'/_template.txt');
if( !$tpl ) {
  for( $dir = dirname($dir); !$tpl && $dir != $conf['datadir'] && file_exists($dir); $dir = dirname($dir) ) {
  	$tpl = io_readFile($dir.'/_'.$page.'_template.txt');
		if(!$tpl) $tpl = io_readFile($dir.'/_template.txt');
  }
}
 
wiki/discussion/alternate_namespace_template_file.txt · Last modified: 2007/07/19 06:13 by 220.233.183.232
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate