How to create link with caption as label if caption exists?

I want a link to, say, the tiddler titled “target”.
If “target” has a caption then this is used as the link label, otherwise the title is used.

Seems totally trivial to me at first, but I stumble. Any sensible way to achieve this? (It should behave like links normally do, including italics if “target” is missing, etc)

If you dont want to create your own macro, you can use the list-link macro :

<<list-links "[[Your tiddler]]" span a>>

This will use the field caption if it exist, and put your link in a span. See $:/core/macros/list :

\define list-links(filter,type:"ul",subtype:"li",class:"",emptyMessage)
\whitespace trim
<$type$ class="$class$">
<$list filter="$filter$" emptyMessage=<<__emptyMessage__>>>
<$subtype$>
<$link to={{!!title}}>
<$let tv-wikilinks="no">
<$transclude field="caption">
<$view field="title"/>
</$transclude>
</$let>
</$link>
</$subtype$>
</$list>
</$type$>
\end
2 Likes

Try this:

<$link to="target">
<$transclude tiddler="target" field="caption">target</$transclude>
</$link>
2 Likes

@telumire - clever!

@EricShulman - Aaa-haaa! :grinning_face_with_smiling_eyes:

Mucho thanko guys!

The linkyfy macro in kookma Utility, shows the link to tiddler and whatever field you ask, if not existed it uses the title. like <<linkify target description>>.

See also: Link to Tiddler by any Field - Tips & Tricks - Talk TW (tiddlywiki.org)

1 Like