[pmwiki-users] How to start to write a recipe

ThomasP pmwikidev at sigproc.de
Wed Sep 26 06:06:32 CDT 2007


On Wed, September 26, 2007 09:52, Matthias Günther wrote:
> Hello,
>
> I want to start to create a recipe. I looked over the pmwiki documentation
> but
> there I found nothing. It would be nice if someone can post a simple
> example
> which has the following function:
>
> - include the recipe on my wiki like (:test:)
> - when I include this markup then a phrase like "Jeah it worked!!!" should
> be
> displayed in my wiki
>
Hello Matthias,

On Wed, September 26, 2007 09:52, Matthias Günther wrote:
> Hello,
>
> I want to start to create a recipe. I looked over the pmwiki documentation
> but
> there I found nothing. It would be nice if someone can post a simple
> example
> which has the following function:
>
> - include the recipe on my wiki like (:test:)
> - when I include this markup then a phrase like "Jeah it worked!!!" should
> be
> displayed in my wiki
>

Hello Matthias,

try the following:

Create a file yeah.php in the cookbook directory with the lines

<?php if (!defined('PmWiki')) exit();
Markup('myYeah','inline','/\\(:test\\s+(\\S.*?):\\)/ei',
"MyYeahFunction('$1')");
function MyYeahFunction($arg) { return "Yeah, $arg works.<br>"; }

and include this file into your configuration by adding

include_once("cookbook/yeah.php");

in your local/config.php.

This will register a markup of the form (:test my_argument:) that allows
passing a parameter to the given function. The exact choice of the
parameters to the function Markup() might take some time to be fully
appreciated, but just the following explanation:

- the 1st argument is the "name" of the markup used internally for
referencing the markup rule
- the second argument determines in which section the markup is executed.
(As the order in which markup replacements are done matters, this might
need some good deal of consideration, and sometimes experimentation, in
practice.)
- the third is a regular expression used for searching the markup in the
text.
- the fourth is what function is executed once a match is found.

Have a look at [1] for more details.

Thomas

[1] http://www.pmwiki.org/wiki/PmWiki/CustomMarkup






More information about the pmwiki-users mailing list