2013-03-04 11:13:10 +00:00
title: LinkWidget
2013-08-25 20:41:00 +00:00
tags: widget
2013-03-04 11:13:10 +00:00
2013-10-23 22:12:19 +00:00
The `link` widget generates links to tiddlers.
2013-03-04 11:13:10 +00:00
2013-10-23 22:12:19 +00:00
! Content and Attributes
2013-03-04 11:13:10 +00:00
2013-10-23 22:12:19 +00:00
|!Attribute |!Description |
2013-11-01 15:00:17 +00:00
|to |The title of the target tiddler for the link (defaults to the [[WidgetVariable: currentTiddler]]) |
2014-03-08 16:06:57 +00:00
|tooltip |Optional tooltip WikiText |
2013-03-04 14:42:41 +00:00
2013-10-23 22:12:19 +00:00
The content of the link widget is rendered within the `<a>` tag.
2013-03-04 11:13:10 +00:00
2014-03-09 09:16:31 +00:00
The default value of the tooltip attribute is `<<tw-wikilink-tooltip>>`. If that variable is not defined then the following text is used:
2014-03-08 16:06:57 +00:00
```
<$transclude field="tooltip"><$transclude field="title"/></$transclude>
```
2014-03-09 09:16:31 +00:00
This means that you can control the text of a link tooltip in several ways:
```
<$link to="HelloThere" tooltip="Custom tooltip">Link 1</$link>
<$set name="tw-wikilink-tooltip" value="I'm a link to {{!!title}}">
<$link to="HelloThere">Link 2</$link>
</$set>
```
Renders as:
<$link to="HelloThere" tooltip="Custom tooltip">Link 1</$link>
<$set name="tw-wikilink-tooltip" value="I'm a link to {{!!title}}">
<$link to="HelloThere">Link 2</$link>
</$set>
2014-03-08 16:06:57 +00:00
Note that the tooltip is rendered with the current tiddler set to the target of the link.
2013-03-04 11:13:10 +00:00
! CSS Classes
2013-03-04 14:42:41 +00:00
* `tw-tiddlylink` - applied to all links
* `tw-tiddlylink-external` - applied to external, non-tiddler links
* `tw-tiddlylink-internal` - applied to tiddler links
* `tw-tiddlylink-missing` - applied to tiddler links where the target tiddler doesn't exist
* `tw-tiddlylink-resolves` - applied to tiddler links when the target tiddler does exist
2013-03-04 11:13:10 +00:00
! Configuration macros
Configuration macros can be used to modify the behaviour of the link widget.
!! tw-wikilinks
Links are suppressed if the macro `tw-wikilinks` evaluates to the string `no`. For example:
```
\define tw-wikilinks() no
```
!! tw-wikilink-template
2014-03-08 16:06:57 +00:00
The target of the link widget defaults to the URL encoded title of the tiddler. The `href` can be templated by defining the configuration macro `tw-wikilink-template`, and including within it the token `$uri_encoded$`. For example:
2013-03-04 11:13:10 +00:00
```
\define tw-wikilink-template() http://tiddlywiki.com/#$uri_encoded$
```
2013-10-23 22:12:19 +00:00
2014-03-08 16:06:57 +00:00
The token `$uri_doubleencoded$` is replaced by the double encoded title of the tiddler.
2013-10-23 22:12:19 +00:00
Note that in the browser the `<a>` element generated by the link widget has a JavaScript event handler that navigates directly to the target tiddler, ignoring the `href` attribute.
2014-03-08 16:06:57 +00:00
!! tw-wikilink-tooltip
Provides default text for the link tooltip:
```
\define tw-wikilink-tooltip() This is a link to {{!!title}}
<$link to="HelloThere"/>
```