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

Randy Brown randy at brownragfilms.com
Thu Dec 19 01:50:18 CST 2013


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
   $BestAvailableTitle = '$Titlespaced';
} else {
   $BestAvailableTitle = 'PageTextVar($pagename,"Summary")';
}
$FmtPV['$BestAvailableTitle'] = $BestAvailableTitle;  
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);   
 }
if (PTVlen($page,"Summary") == 0) {

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

What do I need to do to make this work? 

Note also:  I'm using "/e" in the markup. I think I read that that was deprecated in PHP 5.5. Although I'm not using that PHP version yet, I have no idea how to do this any other way. Suggestions are welcome.

Randy





More information about the pmwiki-users mailing list