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

Petko Yotov 5ko at 5ko.fr
Thu Dec 19 02:35:37 CST 2013


Randy Brown writes:

> When I have a page whose name is a number, I sometimes use the Summary page  
> text variable in pagelists as the page's effective title. To make the markup  
> easier for users, I want to create custom markup similar to PmWiki's  
> [[MyPage|+]] markup. My markup would use the tilde instead of a plus sign,  
> to produce link text with the page's $:Summary, if available, and using the  
> title, or if necessary the page name, if it's not.
>
> Here's what I've written so far:
>
> if …. # I NEED A CONDITIONAL HERE that will evaluate to true if the to-be- 
> saved Summary page text variable will be null
> if (PTVlen($page,"Summary") == 0) {
>    $BestAvailableTitle = '$Titlespaced';
> } else {
>    $BestAvailableTitle = 'PageTextVar($pagename,"Summary")';
> }
> $FmtPV['$BestAvailableTitle'] = $BestAvailableTitle;

First, at this point there is not $page variable.

Even if you have a custom variable containing the current page name, your  
$BestAvailableTitle will be defined for all pages based on the current page.  
So this will not do what you want (it will do what you tell it to do :-).

> Markup('[[|~', '<[[|',
>   "/(?>\\[\\[([^|\\]]+))\\|\\s*\\~\\s*]]/e",
>   "Keep(MakeLink(\$pagename, PSS('$1'),
>                  PageVar(MakePageName(\$pagename,PSS('$1')),  
> '\$BestAvailableTitle')
>                 ),'L')");
>
> I have tried using for the missing conditional the following:
>
>  function PTVlen ($page, $ptv) {
>     $var=PageTextVar($page,$ptv);
>     return strlen($var);
>  }
>

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');
  }

You evaluate the "best title" of every page for every [[link|~]], not once  
based on the current page.

> But when I do that, preview shows the old page text variable values when it  
> previews the page.

"Preview" of posted PTVs was fixed almost 4 years ago in version 2.2.10 -  
before this version PmWiki retrieved the variables from the last saved page  
content.

Petko




More information about the pmwiki-users mailing list