[pmwiki-users] using PTVs from pagelists in skin scripts (or how to register a new PV)

Peter Bowers pbowers at pobox.com
Sat May 12 03:21:30 CDT 2012


On Sat, May 12, 2012 at 9:20 AM, <a.sonderhoff at gassi-tv.de> wrote:

> why does (:var: {=$:var}:) produce an epic fail, while (:title {=$:var}:)
> just works fine?


Maybe if you're this close maybe you can do it with the pagelist solution
you've got.

But PTV's cannot be set dynamically via markup.  The pmwiki functions that
read PTVs do not make use of the text as modified by markup rules but
rather read the original text from the page.  (See below my signature for
the code)

Thus no matter what PTV definitions you may create *via markup* they will
never be recognized, because PageTextVar() never looks at the marked-up
text.

You could theoretically mess with the $PCache and set it manually, but
usually when I've tried to sneak in changes to a cache by some method other
than the standard functions I end up pulling my hair out because of all the
unexpected things that happen with the cache.

Probably what I would do would be to set up your own markup with a set and
a read markup so that in your pagelist template you could have

(:setmyval {=$:foo}:)

(which would set either a static or a global value) and then this markup
when you need the value:

(:readmyval:)

which would simply return that static or global value.

-Peter

===(snip pmwiki.php)===
function PageTextVar($pagename, $var) {
  global $PCache, $PageTextVarPatterns, $MaxPageTextVars;
  SDV($MaxPageTextVars, 500);
  static $status;
  if(@$status["$pagename:$var"]++ > $MaxPageTextVars) return '';
  if (!@$PCache[$pagename]['=pagetextvars']) {
    $pc = &$PCache[$pagename];
    $pc['=pagetextvars'] = 1;
#####
## NOTICE how the page is read from scratch here
#####
    $page = RetrieveAuthPage($pagename, 'read', false, READPAGE_CURRENT);
    if ($page) {
      foreach((array)$PageTextVarPatterns as $pat)
#####
## AND then here we search for PTV patterns on the $page['text'] below
#####
        if (preg_match_all($pat,
IsEnabled($PCache[$pagename]['=preview'],@$page['text']),
          $match, PREG_SET_ORDER))
          foreach($match as $m) {
            $t = preg_replace("/\\{\\$:{$m[2]}\\}/", '', $m[3]);
            $pc["=p_{$m[2]}"] = Qualify($pagename, $t);
          }
    }
  }
  return @$PCache[$pagename]["=p_$var"];
}
===(snip)===
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20120512/bd916d01/attachment.html>


More information about the pmwiki-users mailing list