LinkPageExistsFmtTooltip

Summary: How to add tooltips to links
Status: Stable
Version: 2007-01-15
Prerequisites: pmwiki-2.1
Maintainer:
Categories: Links
Votes:

Question

From version 2.2.14 PmWiki can natively show tooltip titles for external and internal links (anchors and intermap links included) : see Links#tooltiptitle.
How can I add a tooltip (small popup text that is displayed when you run with the mouse over a link) for a link to a existant page ?

Answer

Adding the target page title as a tooltip

Adding a tooltip using the title of the target wiki page is quite straightforward as demonstrated in LinkPageCreateFmtTooltip. Add to config.php:

$LinkPageExistsFmt = "<a class='wikilink' title='{\$Title}' href='\$LinkUrl'>\$LinkText</a>";

Adding the target page description as a tooltip

A description can be added to a page using the (:description ...:) markup.
A title can be added to a page using the (:title...:) markup

To display a page's description as a tooltip instead of the title, use

$LinkPageExistsFmt = "<a class='wikilink' title='{\$Description}' href='\$LinkUrl'>\$LinkText</a>";

To display a page's description, but fall back to the page's title if a description isn't set, use the following:

$FmtPV['$DescriptionT'] =
  '@$page["description"] ?  $page["description"] : PageVar($pn, "\$Title")';
$LinkPageExistsFmt = "<a class='wikilink' title='{\$DescriptionT}' href='\$LinkUrl'>\$LinkText</a>";

Adding an arbitrary text as a tooltip

Use links like [[target | text "tooltip"]]. The tooltip text needs to be inside the double quote marks.

Add to config.php

## [[target | text "tooltip"]]
Markup('[[|tt','<[[|',
  "/(?>\\[\\[([^|\\]]*)\\|\\s*)(.*?)\\s*(\"(.*?)\")?\\s*\\]\\]($SuffixPattern)/e",
  "Keep(ToolTipLink(\$pagename,PSS('$1'),PSS('$2'),PSS('$4'),'$5'),'L')");

function ToolTipLink($pagename, $tgt, $txt, $tooltip='', $suffix) {
  global $FmtV;
  $FmtV['$LinkAlt'] = $tooltip;
  return MakeLink($pagename, $tgt, $txt, $suffix);
}

$LinkPageExistsFmt = "<a class='wikilink' href='\$LinkUrl' rel='nofollow'
   title='\$LinkAlt'>\$LinkText</a>";

Notes

  • This recipe was last tested on PmWiki version: 2.1beta14
  • This recipe requires at least PmWiki version: 2.1beta14
  • This recipe, version 1 was installed here the 22 December 2005

Contributors

Comments

See discussion at LinkPageExistsFmtTooltip-Talk?

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.