quick Template Switch

OBSOLETE BY Template Switcher via Action

Including the DokuWiki version 2006-03-09 there is no option to change the template via button for the current session. That is why I made this little mod. To include this modification into your DokuWiki you will have to change the engine as described below:

In the file /inc/actions.php we have to announce the new functionality. Therefor we add the following into the array array_search within the function act_clean(): ‘template’

Most of the DokuWiki users should have the following line befor the changing:

if(array_search($act,array(	'login','logout','register','save','edit','template'
				'preview','search','show','check','index','revisions',
				'diff','recent','backlink','admin','subscribe',
				'unsubscribe','profile','resendpwd',)) === false

After including the change it should look like this:

if(array_search($act,array(	'login','logout','register','save','edit','template'
				'preview','search','show','check','index','revisions',
				'diff','recent','backlink','admin','subscribe',
				'unsubscribe','profile','resendpwd','template',)) === false



To make the Wiki show the last/actual page after asking for a template change we need to add the following lines inton the function act_dispatch() in the same file:

  if($ACT == 'template'){
  	$ACT = 'show';
  }



Now we need to add a second parameter to the function tpl_button() in the file /inc/template.php. This is important, because we need to tell the function which template should be called. The old function is:

function tpl_button($type){

and you need to change it to:

function tpl_button($type, $additional=NULL){



Within the same function we need to expand the case construct so that the button will be shown lateron:

case 'template':
	print html_btn('template',$ID,'',array('do' => 'template', 'template' => $additional));
	break;



To give the new button something to show, we have to add a description into the file inc/lang/*/lang.php. I took the asterisk for everybody who has to change more than one language. Now, add below the $lang[’btn_*’] lines another one with:

$lang['btn_template']  = 'change Template';



Finaly we will implement the real switching mechanism. Therefore we add a bit of code into the file /conf/local.protected.php, so that it will not be accidentily overwriten by the config plugin or something. It is possible that the file does not exist at all. In that case, please crete it and insert ‘<?php’ into the first line. After that, just add the following code:

session_start();
$_SESSION['template']=empty($_POST['template'])?(empty($_SESSION['template'])?$conf['template']:$_SESSION['template']):htmlspecialchars($_POST['template']);

$conf['template']    = $_SESSION['template'];



So, thats been it. Now you can insert the following code into your template or into your DokuWiki pages 1):

tpl_button('template', 'theOtherTemplate');

Please be aware to add another switching button into theOtherTemplate to change the template back.

Now, thats been really all. And please, don’t forget: these changes are without any guaranty. If anything goes wrong whilest changing the DokuWiki, I will not be liable to it. If there are any questions you are welcome to write a mail.

1) if the php option is set