[pmwiki-users] Custom page variable using FmtPV, want to get it to work from different page

Petko Yotov 5ko at 5ko.fr
Thu Mar 21 18:24:52 CDT 2013


ccox at endlessnow.com writes:
> According to the documentation you can refer to a different page's page
> variable using the syntax {pagename$variable}.
>
> I'm defining some new page variables from $GLOBAL['whatever'] inside of my
> config.php, but they evaluate only for the current page, I can do the
> {pagename$variable} syntax to pull in from other pages.  Is there a way to
> make that work?  Maybe a sample FmtPV I could look at that simply pull
> something in somehow... I figure with a good example, I can figure it out
> from there.

Here is an example:

  $FmtPV['$YourVariable'] = 'YourFunction("$group.$name", $page["title"])';
  function YourFunction($pagename, $targetpagetitle) {
    global $Whatever;

    # do something with $pagename
    $uppercase = strtoupper($pagename);

    # or, instead of RetrieveAuthPage(), just use PageVar()
    $mytitle = PageVar($pagename, '$Title');
    $myvalue = PageVar($pagename, '$:MyTextVar');

    # return something
    return $Whatever . $myvalue;

  }

The "$group.$name" part will be supplied automatically according to the  
target page, so {$Var} will refer to the current page, {OtherPage$Var} will  
refer to the other page ("$group.$name" will be passed as  
"Group.OtherPage").

If you have the patience, you can read the definitions of the default page  
variables in pmwiki.php, lines 121-151 approximately.

Petko




More information about the pmwiki-users mailing list