Overriding links with captions

I followed a thread a while ago Exploring default tiddler links hackability in V5.3.0 and was hoping to see it get down to a minimal sample that I could use for other purposes. A simple example would be to have a standard [[Long tiddler title]] entered but it’s caption (if it has it) used as the text for the link. This would be helpful to me for storing things in a proper unique format, but having a simple or abbreviated piece of text while reading.

I’m finding that really nailing this will help me (and maybe others) understand some of the newer stuff too (\widget, $parameters, $genesis, $slot…)

Dragging Big Long Title.json (1.7 KB) into TiddlyWiki should show you something like this:

In my examples below, a next step of understanding is understanding why the examples 3, 4, and 5 don’t show BLT like example 1. I’m glad #2 and #6 let you override things and wouldn’t want to change that.

2 Likes

The original thread was in aid of dealing only with [[links and with spaces]] or camelcase including missing links. Personaly I wanted to use it to add smart prefixes or suffixes to these links.

I will review in detail tomorrow as I have learned a lot since I raised it.

In your problem cases why not use a full link widget, procedure or different custom widget because you are writting the code unlike the aforementioned standard links?

Try

\function caption.or.title() [{!!caption}else{!!title}]

<$link><<caption.or.title>></$link>

My more long-term need is something similar to your “smart prefix” concept. I prefix my tiddlers with characters denoting whether it’s a person, project, goal, etc. I want to use this type of customization to display additional informational characters based on some logic.

For the above though, I kind of journal and write things dozens of times per day like "I talked with [[@ Firstname Lastname]] about [[# Long name of project that I’d prefer abbreviated]] and [[Other firstname lastname]] will follow up with me by [[% 2023-12-20]]. I use autocomplete to help write that, but as it’s displayed in an outliner, I’d prefer to have it only show me the captioned form of each of those tiddlers.

Consider marios alias plugin called uni-link.

However I will explore a function or procedure to assist.

  • how do you obtain the tiddler titles in the first place?

Also I am happy to join you on a small collaboration to find a shared solution and I have done 95% of it with a tag driven prefix/suffix already.

  • given your use case we can include a way to enable the same logic on other links not just the default wiki links.

I appreciate you trying to help, but my original post is what I’m trying to solve and is intended as a minimal use case. As I stated, having such a “real world” example will help for my future understanding of many of the new features I outlined, and so a change of my question or solving an entirely different way is not helpful to me in this case. We can circle back once I figure this out if you’d like though.

Ok, I have what looks like a solution;

  • I hope this goes someway to helping your understanding, it gets a lot easier.
  • Of course built with the help of others as it was my first custom widget.

See this line gets the caption if available, and not given if in the calling of $link widget.

<$slot $name=ts-raw><$text text={{{ [<to>get[caption]else<to>] }}}/></$slot>

The custom widget that redefines the default,

\widget $link()
\whitespace trim
<$parameters to=<<currentTiddler>> $params="@params">
<$list filter="[tag[$:/tags/before-links]]" variable=tiddlername>
<$transclude tiddler=<<tiddlername>>/>
</$list>
<$genesis
  $type="$link"
  $remappable="no"
  $names="[<@params>jsonindexes[]]"
  $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>]">
<$slot $name=ts-raw><$text text={{{ [<to>get[caption]else<to>] }}}/></$slot>
</$genesis>
<$list filter="[tag[$:/tags/after-links]]" variable=tiddlername>
<$transclude tiddler=<<tiddlername>>/>
</$list>
</$parameters>
\end $link
  • Tagged $:/tags/Global/View/Body (to restrict it to in tiddlers in the story.)

So I tested

* [[tiddler]]
* [[alt|tiddler]]
* [[Link to big long tiddler]]
* <$link/>
* <$link to="Link to big long tiddler"/>
* <$link to="Link to big long tiddler">something else</$link>

* [[tiddler with object-type]]
* [[tiddler without object-type]]

Giving this

  • The more icon is because I have a tiddler tagged $:/tags/after-links that provides a drop down to select the object-type field from a list
    • The tiddler with an object type does not have the dropdown
    • The missing tiddler also does not have an object-type because it does not exist
    • However in the image I am selecting it.
      • As soon as a tiddler has an object-type its gets its own cascade templates. Thus as soon as I see a link to a tiddler listed I can create and assign the object-type.
  • You could of course create missing tiddlers from a selected tiddler template if desired.

[Note]

  • I needed to find a way to reduce the links in which this appears.
  • Tag with $:/tags/Global/View/Body (to restrict it to in tiddlers in the story.)

This simpler version, with a custom name only uses caption if needed;

* <$link.caption/>
* <$link.caption to="Link to big long tiddler"/>
* <$link.caption to="Link to big long tiddler">something else</$link. Caption>

The custom widget

\widget $link.caption()
\whitespace trim
<$parameters to=<<currentTiddler>> $params="@params">
<$genesis
  $type="$link"
  $remappable="no"
  $names="[<@params>jsonindexes[]]"
  $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>]">
<$slot $name=ts-raw><$text text={{{ [<to>get[caption]else<to>] }}}/></$slot>
</$genesis>
</$parameters>
\end $link.caption
  • I do not know what remappable is about so removed it. warning It just bricked my wiki. $remappable="no" is needed but not in the documentation.

Thanks! The modified emptyMessage code captured the rest of the cases. Now to try repeatedly breaking it to try and understand it… :slight_smile: