[Pmwiki-users] Re: Set variables in page and use them

Patrick R. Michaud pmichaud
Mon Jul 26 16:13:31 CDT 2004


On Mon, Jul 26, 2004 at 10:25:55PM +0200, Albi Rebmann wrote:
> >I have a 20 simular pages on pmwiki, only difference is one word.
> >Now my idea is, can I set this word into a variable and make a include 
> >page. In this include page I would write the variable. So normal page 
> >has only "set variable" and include line.
> >Is this possible in any way? Thanks for any help.
> 
> Looks like it is not possible, or there any other reason for no answers?

No, it's actually possible in lots of different ways--sometimes it just
takes a day or two for an answer to show up (especially since this is
popular vacation time for many in the northern hemisphere).

Yes, you can set a variable that would be used in another page.  Try
something like this:

  <?php
    $DoubleBrackets['/\\[:setmyvar (.*?):\\]/e'] =
      "substr(\$myvar='$1',0,0)";
    $DoubleBrackets['/\\{\\$myvar\\}/e'] = "\$myvar";
  ?>

The first statement enables markup of the form [:setmyvar <value>:], which
sets $MyVar to be <value>.  (The substr call is just a way of replacing
the directive with an empty string.)  The second statement enables 
markup of the form {$myvar}, which is replaced with the current value
of $myvar.

Thus you can put 

   [:setmyvar some text here:]
   [[include SomeOtherPage]]

and inside of SomeOtherPage the markup {$myvar} will be replaced
with "some text here".

Pm



More information about the pmwiki-users mailing list