Translations of this page?:

newpagetemplate Plugin

newpagetemplate plugin by Jason Grout
Loads predefined page content from a given template

Last updated on 2007-02-24. Provides Syntax.
Compatible with DokuWiki 2006-11-06.

Tagged with editing, pagetemplate, template.

Download http://math.byu.edu/~grout/newpagetemplate.zip

Description

This plugin loads into the new page creation box a template specified in the $_REQUEST “newpagetemplate” parameter. Effectively, this means that you can pass a template page, similar to the namespace template pages, either in the URL or in a POST form to the creation page. Also, you can pass any number of substitution variables in the “newpagevars” variable.

See the addnewpage plugin discussion to see how to modify the addnewpage plugin to take advantage of this feature.

Example

If a new page is created with the URL:

doku.php?id=:mynewpage&do=edit&rev=&newpagetemplate=:pagetemplates:homepagetemplate&newpagevars=@HI@,Howdy!

then the :pagetemplates:homepagetemplate page is pasted into the edit box. If the “standardreplace” configuration option is true, then the substitutions noted below are performed. If the “userreplace” configuration option is true, then you can also replace ”@HI@” with “Howdy!”, as this substitution was passed in newpagevars. The format for newpagevars is: newpagevars=key,value;key2,value2;key3,value3;

Substitutions

As with the _template.txt namespace templates, the following variables are replaced in your template.

@ID@ the new page id
@NS@ the new page's namespace
@PAGE@ the new page's name
@USER@ the creating user's username
@NAME@ the creating user's real name
@MAIL@ the creating user's email
@DATE@ the date

Discussion

Could anybody provide me a simple description or example for the usage of the plugin in combination with 'addnewpage'?

Thanks, Matt

I've found a potential bug; the @ID@ replacement and related @PAGE@/@NS@ do not work; the $id variable seems not to be defined; I've solved it by modifying the function pagefromtemplate as follows:

  • added global $ID;
  • changed all $id instances with $ID

- Sergio, 1 Apr 2007

I also had to Sergio's suggestion to get the standard replace functions to work. New function works and looks like:

  function pagefromtemplate(&$event, $param) {
     if(strlen(trim($_REQUEST['newpagetemplate']))>0) {
       global $conf;
       global $INFO;
       global $ID;

       $tpl = io_readFile(wikiFN($_REQUEST['newpagetemplate']));

       if($this->getConf('userreplace')) {

         $stringvars=array_map(create_function('$v', 'return explode(",",$v,2);'),
                               explode(';',$_REQUEST['newpagevars']));
         foreach($stringvars as $value) {
           $tpl = str_replace(trim($value[0]),trim($value[1]),$tpl);
         }
       }

       if($this->getConf('standardreplace')) {
         $tpl = str_replace('@ID@',$ID,$tpl);
         $tpl = str_replace('@NS@',getNS($ID),$tpl);
         $tpl = str_replace('@PAGE@',strtr(noNS($ID),'_',' '),$tpl);
         $tpl = str_replace('@USER@',$_SERVER['REMOTE_USER'],$tpl);
         $tpl = str_replace('@NAME@',$INFO['userinfo']['name'],$tpl);
         $tpl = str_replace('@MAIL@',$INFO['userinfo']['mail'],$tpl);
         $tpl = str_replace('@DATE@',date($conf['dformat']),$tpl);
       }
       $event->result=$tpl;
       $event->preventDefault();
     }
  }

When accessing a non-existing page you're provided with a text: This topic does not exist yet
You've followed a link to a topic that doesn't exist yet. If permissions allow, you may create it by using the Create this page button

It would be nice to add text where the user can choose from different templates, your plugin would then provide the url to match the name of the page and the user has choice from different templates. Or am I missing something here ?

I have a same question. Can anybody explain me how to use a new page template when adding a page. I am new to PHP and don't know anything. Your help is highly appreciated.

Thanks George

 
plugin/newpagetemplate.txt · Last modified: 2008/08/06 16:37 by 64.46.248.204
 

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