[pmwiki-users] custom markup - call of method (not function) possible

Patrick R. Michaud pmichaud at pobox.com
Mon Feb 7 16:35:54 CST 2005


On Mon, Feb 07, 2005 at 11:15:04PM +0100, Patrick Ogay wrote:
> 1a)Works:  (:$PageCount :) -> 25
> Markup('{$PageCount}','>{$var}','/\\(:\$PageCount:\\)/e',@$PageCount);     
> 
> 1b)doesn't work:
> $SiteStats =  "<table><td><tr>.... </table>"
> Markup('{$SiteStats}','>{$var}','/\\(:\$SiteStats:\\)/e',@$SiteStats);

The problem is that "/e" in the regexp -- with that it's trying to
execute the value of $SiteStats as PHP code.  For $PageCount it was
okay, because the result of executing "25" is indeed 25, but trying
to execute "<table><td><tr>...</table>" in PHP will give you a parse
error.  :-)

Best is probably the following, assuming the value of $SiteStats won't
change from when it's first initialized:

    Markup('{$SiteStats}', '>{$var}', 
      '/\\(:\\$SiteStats:\\)/', 
      Keep($SiteStats));

If $SiteStats will change, you want
    Markup('{$SiteStats}', '>{$var}', 
      '/\\(:\\$SiteStats:\\)/e', 
      "Keep(\$GLOBALS['SiteStats'])");


> 2a) Works:
> Markup('PageCount', 'directives', '/\\(:$PageCount:\\)/e',"ftest()");
> 2b) doesn't work:
> Markup('PageCount', 'directives', '/\\(:\$PageCount:\\)/e',"$po->ftest1");
> doesn't work
> Markup('PageCount', 'directives', '/\\(:\$PageCount:\\)/e',"\$po->ftest1");
> does nothing

... because when the markup code is actually executed (inside of the
Markup2HTML() function), the variable $po isn't defined.  
If $po is a global variable, you want:

    Markup('PageCount', 'directives',
      '/\\(:\\$PageCount:\\)/e',
      "\$GLOBALS['po']->ftest1");

> Is it possible to call methods in the skin, I didn't try yet.

Sure, just remember that anything in skin.php is being called from
within the SetSkin() function, so that variable references aren't
global by default.

Pm



More information about the pmwiki-users mailing list