[pmwiki-users] Defining a variable in a wiki page

Américo Albuquerque aalbuquerque at lanowar.sytes.net
Wed Apr 19 20:02:32 CDT 2006


Patrick R. Michaud wrote:
(...)
> 
> Part of the problem is one of sequencing -- with PmWiki's
> existing markup rendering engine it's hard to have both
> 
>     (:set Name Tom:)
>     (:if equal $Name Tom:)
>     ...
>     (:if:)
> 
> and
> 
>     (:if condition:)
>     (:set Name Tom:)
>     ...
>     (:if:)
> 
> because if we process the "(:set:)" markup first, it will ignore
> the conditional, and if we process the "(:if:)" markup first,
> we can't use values from "(:set:)" as part of the conditional.
> 

This is my first PmWiki cookbook script but I think it works as expected

add include_once("$FarmD/cookbook/variables.php"); in your config.php

and create a page using the special markups:

(:set varname "var value":) - saves the string 'var value' into the
variable 'varname'. The double quotes are required for the thing to work.

(:vardump:) show all saved variables (not the $FmtPV var but the 
internal variable used to check if a set is inside or outside a if). 
This Markup is used just for testing. This Markup won't display anything 
if $VariableTest is set to 0 (it's default value)

The variables are saved in $FmtPV and assessible using the {$varname} 
syntax.

To test it just create a page with:
!!Testing Variables Cookbook

(:set var1 "test":)

(:set var "testing":)

(:if equal '{$var1}' 'teste':)
!!!! Set inside a if
(:set var2 "variable 2":)
(:ifend:)

(:set var3 "variable testing":)

(:vardump:)

'''var:''' '{$var}'

and see the result.

Hope this helps
Américo Albuquerque
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-users/attachments/20060420/bd861cd7/attachment.html 


More information about the pmwiki-users mailing list