[pmwiki-users] How to make a link whose text is a page text variable

Petko Yotov 5ko at 5ko.fr
Sat Dec 21 17:05:43 CST 2013


Randy Brown writes:
> > Something like this may work:
> >
> >  Markup('[[|~', '<[[|',
> >    "/(?>\\[\\[([^|\\]]+))\\|\\s*\\~\\s*]]/e",
> >    "Keep(MakeLink(\$pagename, PSS('$1'),
> >      BestTitle(MakePageName(\$pagename,PSS('$1')))
> >      ),'L')");
> >
> >  function BestTitle ($pn) {
> >    $sum = PageTextVar($pn,'Summary');
> >    if (strlen($sum)) return $sum;
> >    else return PageVar($pn, '$Title');
> >  }
>
> Thanks, Petko. That seems to work.
>
> If I don't run into problems, maybe I should post this as a recipe called  
> "Best Title: Use A Page Text Variable For Link Text when available".  
> However, if the "/e" only works for versions before PHP 5.5, then maybe I  
> shouldn't. What do you think?

The following will work with PHP 5.5 (but requires at least pmwiki-2.2.56):

  Markup_e('[[|~', '<[[|',
    "/(?>\\[\\[([^|\\]]+))\\|\\s*\\~\\s*]]/", # replace ending /e with /
    "Keep(MakeLink(\$pagename, PSS(\$m[1]),
      BestTitle(MakePageName(\$pagename,PSS(\$m[1])))
      ),'L')");                               # replace '$1' with \$m[1]

I'll document the new ways to define custom markup after I release 2.2.58  
in a few days (the old ways still work and will not be removed).

Petko




More information about the pmwiki-users mailing list