HrefPageDirective

Summary: How to get the href address to a particular wiki link
Version:
Status:
Maintainer: MarkS
Categories: Links

Question

How can I get the href address to a particular wiki link?

Answer

  • Use the built-in page variable {$PageUrl} that contains the page URL. Demo below. --Petko
* Current page: {$PageUrl} 
* Other page: {Main.HomePage$PageUrl} 

Recipe for old PmWiki versions

Prerequisites: requires at least PmWiki version: 2.0.10 (should work on earlier versions); last tested on PmWiki version: 2.0.10 and version 2.1.26

Allow a (:href Main.StaffInfo :) Page Directive.

Example code to get this working;


if (defined('PmWiki')){
    ## (:href Main.StaffInfo :)

    Markup("href","<{$fmt}",
      "/\\(:href\\s(.*?)\\s*:\\)/e",
      "Keep(getHrefFromWikiLink(\$pagename,PSS('$1')),'L')");

}

function getHrefFromWikiLink($pagename, $tgt=NULL, $txt=NULL){
    #echo "getHrefFromWikiLink";
    $link = MakeLink($pagename,$tgt,$txt);

    $hrefToken = "'";
    $hrefStart = strpos($link, "'", strpos($link, "href"));    
    $hrefStop = strpos($link, "'", $hrefStart + 1);
    $hrefText = substr($link, $hrefStart + 1, $hrefStop - $hrefStart - 1);
    #echo $hrefText;
    return $hrefText;   
}

Notes

  • The "<" value is important and could be changed depending on what order you want the directive to execute in
  • It all hinges on the form of what the pmwiki "MakeLink" function returns.

Releases

Contributors

MarkS

Comments

See discussion at HrefPageDirective-Talk?