Use tiddler's caption for link if it exists?

Hi,

I have a wiki where many tiddlers that use the caption field to provide a more readable name. Is it possible to modify all links in TiddlyWiki to display the link target’s caption field instead of the title field? If it helps, I have upgraded my wiki to the latest 5.3.0.

From what I understand, 5.3.0 allows to globally redefine a widget, so it should be possible to redefine $link widget in such a way, that it would display caption if available. You wouldn’t have to touch the links in the wikitext then, just change how links work in general. Also changing captions wouldn’t be a problem then.
But I can’t tell you how to do that exactly, just letting know it should be doable in 5.3.0.

There was a discussion on this prior to 5.3.0s official release but note that some lists alread do this and many make use of the list item template and you could modify and use that. You only miss links generated in wiki text.

Thanks, I just figured it out. This is the $link override widget I just created.

\widget $link(to)
\whitespace trim
<$parameters to=<<currentTiddler>> tiddler=<<storyTiddler>> $params="@params">
  <$genesis $type="$link" $remappable="no" $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>]" class={{{ [<class>] [<to>tag[dead]then[muted]] +[join[ ]] }}} >
   <$view format="text" field="caption" tiddler=<<to>>>
    <$slot $name=ts-raw><$text text=<<to>> /></$slot>
   </$view>
  </$genesis>
</$parameters> 
\end

That’s nice. But be aware that every link is changed.

  • Tiddler titles in the story-view will also show the caption instead of the title.

This will have all sorts of side effects. That’s OK if you are aware of them. … So be careful!

Since the link widget is such an intergal part of tiddlywiki there may come to be many reasons to manipulate it, of course if you redefine it more than once, the last will win, so importing a new one will have unknowen results. As a result;

  • You should only apply it localy, to the current tiddler or according to a condition.
  • Alternativly there would be value in building a new hackable version that allows various features to be added via tags and other methods as does much of tiddlywikis hackable mechnisiums.

Thus I think it would be wise to collect together a number of desirable hackabilities and build them into a single solution. Here are a few ideas;

  • Ability to tag tiddlers to become a prefix or suffix to any link (I have one already)
  • Allow the ability to alter the list template used so you can introduce alternative code such as in the OT use the caption first if available.
    • An option may be to indicate when a link is a caption and provide a tooltip with the full tiddler name (if desired)
  • Another mechanisium may be to allow a display filter to determin if the link is displayed according to a condition. This would allow some links to be hidden from casual users, or in a different mode.
  • On hover provide a tooltip to the description or tooltip on a tiddler, perhaps tooltip first else description.
  • Perhaps we can introduce something similar to external links?

What other possibilities are there?

I agree @TW_Tones. In particular, I’d like the option to conditionally display things depending on their “object-type” (usually noted via tag, field or title prefix) and would like it for both regular [[link]] and <$link/> links. For example, if I would love it so that if I made a link to something like [[Project A]] I could have it both show a bit differently - prefix, icon, coloring etc. and with a tooltip like you’re saying. Then I’d do a template for [[Person A]], …

I guess I want similar functionality that’s commonly used at the tiddler level - available for links. Maybe that’s an example to build from.

For example for the body of a “project” (tiddler with the tag project) I can:

  • Add a tiddler like $:/stobot/ViewTemplate
  • Tag it $:/tags/ViewTemplate.
  • Have it contain something like:
<$list filter="[all[current]tag[Project]]" variable="ignore">
<$transclude $tiddler="$:/stobot/ViewTemplate" mode="block"/>
</$list>

Now unlike ViewTemplate we probably don’t want to keep adding things, so maybe it’s instead implemented with a cascade where you can do some conditional interrupts to set new templates, and if it doesn’t match then the standard one is the fallback.

If it was implemented in that way, where you essentially can customize a template tiddler, it seems like that’d be the most flexible.

1 Like

@stobot it looks like we are interested in the same thing. For standard wiki links I have a working example of prefix and suffix addition in a redefined link widget.

Perhaps we start another thread.

  • I wonder if we can conditionaly set a class to the link and handle alternative styling in css?
  • I think the cascade is a good idea but I am not sure if its will work inside a redefined widget.
  • I feel there is value adding such features to list items without doing it through the core widget, except to provide an alternative list item template, class, prefix and suffix.

Although I want to maintain an open mind.

Sure @TW_Tones I just tried a couple of things. I’d hoped that from a styling standpoint maybe I could hack something like:

<style>
a.tc-tiddlylink-resolves {
  color:{{{ [<currentTiddler>prefix[Proj]then[red]else[green]] }}};
}
</style>

That doesn’t work obviously, not sure if there’s anything even close to that. I’m inclined to think we don’t have a lot of options other than some of the core stuff like $:/core/modules/parsers/wikiparser/rules/wikilink.js or $:/core/modules/widgets/link.js but alas I don’t speak javascript, and reading through it doesn’t immediately tell me how we could modify that - just out of my league.

We could do something simple like a macro like <<link "Project A">> which we could translate into whatever html/css we want, but I don’t find that as interesting. You mentioned redefining the link widget which I assume is based on the new ability to make widgets that overwrite core. That’s interesting, but I’m most interesting in hacking the standard [[Project A]] type of link, as that’s the one I write “manually”. I’m most interested in intercepting between [[Project A]] and it’s rendered <a class="tc-tiddlylink tc-tiddlylink-resolves" href="#Project%20A">Project A</a>.

This and camel case links make use of the $link widget, so modifying it can modify the behaviour you ask. As I said I have a working example of this that adds content before or after such links when detected.

  • Modifying core tiddlers is not recommended, but overriding them with the new features possibly the next best thing, unless we want the change to become part of TiddlyWiki.

I have just spent more than an hour dealing with some erratic behaviour in FireFox after working with this, so I need to proceed with caution.

I have been thinking of something similar, which is to prefix the link with an icon based on the tiddler’s object type tag. Again, this applies globally across the wiki so the caveats cited by pmario and others apply.

\function .tagicon(tiddler) [<tiddler>tags[]] :intersection[list[TagIcon]] +[first[]get[icon]] 

\widget $link(to)
\whitespace trim
<$parameters to=<<currentTiddler>> tiddler=<<storyTiddler>> $params="@params">
  <$genesis $type="$link" $remappable="no" $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>]" class={{{ [<class>] [<to>tag[dead]then[muted]] +[join[ ]] }}} >
    <$image source={{{ [.tagicon<to>] }}} class="tc-icon" />
    <$slot $name=ts-raw><$text text=<<to>> /></$slot>
  </$genesis>
</$parameters> 
\end

The above code makes two assumptions

  • TagIcon is a tiddler with a list field that list all object types with an icon in the wiki (eg, Person, Location, Organization and so on)
  • Every object type tiddler, for example Person, has an icon field.
1 Like

I’m afraid I am not familiar with TW’s internal mechanics. How would I limit it to only working when rendering a tiddler’s text?

Putting your custom widget definition in a tiddler tagged $:/tags/Macro/View/Body (instead of $:/tags/Macro) will make the definition available within the body segment of the view template.

This technique is used by the core for the “visible transclusion” demo, which redefines the transclude widget to make transclusions directly visible: https://tiddlywiki.com/#Visible%20Transclusions:[[Visible%20Transclusions]]%20%24%3A%2Fcore%2Fui%2FVisibleTransclude