[pmwiki-devel] Creating a page text variable in a recipe

Peter Bowers pbowers at pobox.com
Sun Sep 27 15:08:57 CDT 2009


On Sun, Sep 27, 2009 at 9:02 PM, Hans <design5 at softflow.co.uk> wrote:
> Sunday, September 27, 2009, 7:10:57 PM, Simon wrote:
>
>> I want a variable associated with a particular wiki page
>> (cf {PageName$PageVariable} or {PageName$:PageTextVariable}
>
>> that is set by the recipe and saved as part of the page contents.
>
> in your function you need something like this:
>  //first get the page text content
...
>
>  $text .= "\n(:$key: $val:)";

The difficulty with doing this in your recipe is that each time the
markup runs (i.e., each time someone reads the page) you will append
another (duplicated) PTV definition to the text of your page.  Using
logic such as writeptv() or ptv2text() from toolbox.php (I'm sure fox
and other recipes have the same logic built into them -- toolbox is
just where I know you can get to it easily and it's already "packaged"
for reusability.) will allow you to replace the PTV definition if it
already exists...

The logic for updating a PTV on the page looks like this using toolbox:

if (pagetextvar($pn, $var) != $val) {
   writeptv($pagename, $pn, $var, $val);
   Redirect($pn);
}

(Redirecting as Hans suggests rather than messing with $PCache as I
suggested earlier is an easier solution.)

-Peter



More information about the pmwiki-devel mailing list