[pmwiki-users] Markup or method to increment/decrement a PTV ("integer") variable?

Peter & Melodye Bowers pbowers at pobox.com
Thu Jun 5 16:46:52 CDT 2008


> Subject: [pmwiki-users] Markup or method to increment/decrement a PTV
> ("integer") variable?
> Does it exists? How could it be done?
> Kind regards,

Do you want to change the value temporarily or permanently?  Is it just for
this load of the page or are you wanting to save it back to the page so it
will load in its incremented state the next time as well?

If you just want to increment it temporarily for this load then WikiSh
contains that functionality with the {earlymx(set --ptv ...)} capability.

If you want to save the value back to the page then you're probably going to
have to come up with a quick function to do it yourself.  If you're
interested I have recently put together a "toolbox" recipe (toolbox.php)
which is still under development but it has a function writeptv() which
would make this job very easy.  It's not yet documented on the cookbook
page, but the arguments are fairly self explanatory.  This is basically what
it's going to look like for your functionality:

Function incptv($pagename, $pn, $varname)
{
   $val = PageTextVar($pn, $varname);
   $val++; // or $val--;
   writeptv($pagename, $pn, $varname, $val);
}

Then depending on what your desired functionality is you could wrap that in
an MX or some other markup or just have it in your config.php, etc.

Here's a markup definition of (:incptv page varname:) :
Markup('IncPTV', 'inline', 
    '/\\(:incptv\s+(\S+)\s+(\S+)\s*:\\)/e',
    'incptv(\$pagename, "$1", "$2")');

Note this has a bunch of copy/pasted sections of code without any compiling
or testing.  There will certainly be some fixes needed before any of this
will work.

-Peter




More information about the pmwiki-users mailing list