2014-09-10 23:06:19 +00:00
caption: link
2017-03-29 09:19:42 +00:00
created: 20131024141900000
2019-06-10 20:04:21 +00:00
modified: 20190610195105615
2017-03-29 09:19:42 +00:00
tags: Widgets
title: LinkWidget
type: text/vnd.tiddlywiki
2013-03-04 11:13:10 +00:00
2014-08-28 08:32:19 +00:00
The `link` widget generates links to tiddlers. (Use the HTML `<a>` element to generate external links).
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
2019-06-10 20:04:21 +00:00
The content of the link widget is rendered within the `<a>` tag representing the link. If the content is empty then the title of the target tiddler is rendered as the default.
For example, `<$link to="HelloThere"/>` is equivalent to `<$link to="HelloThere">HelloThere</$link>` and `<$link/>` is equivalent to `<$link to=<<currentTiddler>>><$view field="title"/></$link>`.
2013-10-23 22:12:19 +00:00
|!Attribute |!Description |
2015-02-24 16:41:16 +00:00
|to |The title of the target tiddler for the link (defaults to the [[current tiddler|Current Tiddler]]) |
2017-12-12 12:25:06 +00:00
|aria-label |Optional accessibility label |
2014-03-08 16:06:57 +00:00
|tooltip |Optional tooltip WikiText |
2015-02-23 10:16:44 +00:00
|tabindex |Optional numeric [[tabindex|https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/tabIndex]] |
|draggable |"yes" to enable the link to be draggable (defaults to "yes") |
|tag |Optional tag to override the default "a" element |
2017-12-12 12:30:34 +00:00
|class|Optional CSS classes //in addition to// the default classes (see below)|
|overrideClass|<<.from-version "5.1.16">> Optional CSS classes //instead of// the default classes |
2013-03-04 14:42:41 +00:00
2019-06-10 20:04:21 +00:00
The draggable functionality is equivalent to using the DraggableWidget with the ''tiddler'' attribute set to the link target.
2013-03-04 11:13:10 +00:00
2015-02-28 14:45:22 +00:00
The default value of the tooltip attribute is supplied by the <<.vlink tv-wikilink-tooltip>> variable.
2014-03-08 16:06:57 +00:00
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>
2014-08-28 21:28:02 +00:00
<$set name="tv-wikilink-tooltip" value="I'm a link to {{!!title}}">
2014-03-09 09:16:31 +00:00
<$link to="HelloThere">Link 2</$link>
</$set>
```
Renders as:
<$link to="HelloThere" tooltip="Custom tooltip">Link 1</$link>
2014-08-28 21:28:02 +00:00
<$set name="tv-wikilink-tooltip" value="I'm a link to {{!!title}}">
2014-03-09 09:16:31 +00:00
<$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.
2014-04-08 13:12:27 +00:00
A useful convention is to set the tooltip like this:
```
2014-08-28 21:28:02 +00:00
\define tv-wikilink-tooltip()
2014-04-08 13:12:27 +00:00
<$transclude field="tooltip"><$transclude field="title"/></$transclude>
\end
```
This causes the tooltip to be the ''tooltip'' field of the target tiddler. If the field isn't present, then the title is used instead.
2013-03-04 11:13:10 +00:00
! CSS Classes
2017-12-12 12:25:06 +00:00
The link widget automatically determines and applies the following classes to links:
2014-08-28 17:13:46 +00:00
* `tc-tiddlylink` - applied to all links
* `tc-tiddlylink-external` - applied to external, non-tiddler links
* `tc-tiddlylink-internal` - applied to tiddler links
* `tc-tiddlylink-missing` - applied to tiddler links where the target tiddler doesn't exist
* `tc-tiddlylink-resolves` - applied to tiddler links when the target tiddler does exist
2013-03-04 11:13:10 +00:00
2017-12-12 12:30:34 +00:00
Use the `class` attribute to specify additional css classes, or `overrideClass` to apply only that but not the above defaults, e.g. when used in a LinkCatcherWidget:
2017-12-12 12:25:06 +00:00
<<wikitext-example-without-html """*<$link class="example">Here</$link> the `example` class is added.
2017-12-12 12:30:34 +00:00
*<$link overrideClass="example">Here</$link> only the `example` class applies.
*<$link overrideClass="">Here</$link> no class is set.""">>
2017-12-12 12:25:06 +00:00
2017-08-28 10:06:21 +00:00
! `href` generation
The following process is used to generate the `href` attribute of the generated HTML `<a>` element:
# If <<.vlink tv-get-export-link>> is defined it is invoked to convert the target tiddler title to the `href` value
#* In practice, only a [[JavaScript macro|Macros]] can be used
2017-09-20 10:48:06 +00:00
# <<.from-version "5.1.15">> If <<.vlink tv-filter-export-link>> is defined it is interpreted as a filter that converts the target tiddler title to the `href` value
2017-08-28 10:06:21 +00:00
# If <<.vlink tv-wikilink-template>> is defined it is treated as a specialised macro body that can perform limited conversion of the target tiddler title to the `href` value
# Otherwise, the target tiddler title is URI encoded to create the `href`
2015-02-28 14:45:22 +00:00
! Configuration variables
2013-03-04 11:13:10 +00:00
2015-02-28 14:45:22 +00:00
* <<.vlink tv-wikilinks>>
2017-08-28 10:06:21 +00:00
* <<.vlink tv-filter-export-link>>
2015-02-28 14:45:22 +00:00
* <<.vlink tv-wikilink-template>>
* <<.vlink tv-wikilink-tooltip>>
* <<.vlink tv-get-export-link>>