Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

LinkPageExistsFmtTooltip

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

Question

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

Question: The ideal configuration for me would be to use the quoted link text if the link markup has any (even if linking to an anchor on the current page), otherwise use the page description if it exists and the link is not to the current page. Is there a way to do that? - RandyB
Edit - History - Print - Recent Changes - Search
Page last modified on June 28, 2008, at 08:31 AM