Link to Tiddler by any Field

I have not seen this in Tiddlywiki! But I need a method to create a link to a tiddler, but like to show a field value instead of title!

Is this available in Tiddlywiki?

My Solution

\define linkify(tiddler:"", field:"")
<$link to=<<__tiddler__>> >
<$view tiddler=<<__tiddler__>> field=<<__field__>> >
<$view tiddler=<<__tiddler__>> field="title" />
</$view>
</$link>
\end

If a tiddler has no such field or field is empty, linkify shows the tiddler title. So

<<linkify Test caption>>

Shows My Test on click opens Test tiddler.

To give a try

1 Like

Nice! It reminds me of PMarios’s uni-link :

  • [[anything|?my-field]] … link to alias anything, but display the tiddler-field named my-field

I think, that’s the way it should be done. I did move the thread to the HowTo category. I think it belongs there. … except you want it to be in discussions

\define target() test

<$link to="test"><$text text={{{ [<target>get[caption]else<target>] }}}/></$link>

<$link to="test"><$text text={{{ [<target>] :map[get[caption]else{!!title}]}}}/></$link>
1 Like

Be aware, that :map will start to work with v5.2.0 see: https://tiddlywiki.com/prerelease/#Map%20Filter%20Run%20Prefix

Mohammad,

Thanks for sharing. Yes I have seen this “nested view widgets before”. I think Eric makes use of this. It depends on the fact the

The content of the <$view> widget is displayed if the field or property is missing or empty.

To illustrate this further you can see we can nest further;

\define linkify(tiddler field:"caption")
<$link to=<<__tiddler__>> >
<$view tiddler=<<__tiddler__>> field=<<__field__>> >
   <$view tiddler=<<__tiddler__>> field=caption >
      <$view tiddler=<<__tiddler__>> field="title" />
	 </$view>
</$view>
</$link>
\end

<<linkify test>>

This example also uses caption before the title if it exists.

What is interesting is the field can be the “title” to bypass the caption. But also you can use “text” which results in a form of transclusion that is linked to the source tiddler.

However to further the discussion here is how I would enhance the original macro;

\define linkify(tiddler field:"caption")
<$set name=tiddler value="$tiddler$" emptyValue=<<currentTiddler>> >
<$link to=<<tiddler>> >
<$view tiddler=<<tiddler>> field="$field$" >
   <$view tiddler=<<tiddler>> field=caption >
      <$view tiddler=<<tiddler>> field="title" />
	 </$view>
</$view>
</$link>
</$set>
\end

<<linkify>>

The above defaults to current tiddler so it can be used in any list that changes the currentTiddler, it also defaults to caption, the natural alternative to title. Not also how I depart from the <<__param__>> style, somehow I never became comfortable with that.

Now here is an alternative which does the value nesting in a filter;

\define linkify(tiddler field:"caption")
<$set name=tiddler value="$tiddler$" emptyValue=<<currentTiddler>> >
<$link to=<<tiddler>> ><$text text={{{ [<tiddler>get[$field$]] ~[<tiddler>get[caption]]  ~[<tiddler>get[title]] }}}/></$link>
</$set>
\end

<<linkify test description>>

The value of using the text field as a form of transclusion is interesting, so I may shortly post another variation.

1 Like

I hope its OK for me to “code rant” here.

Based on the value of using the ideas in this thread to create a link to the tiddler, but by displaying the text, not unlike a transclusion, I have made this macro to display a tiddlers “text” content and a link to the tiddler in question.

\define content-link(tiddler)
<$set name=tiddler value="$tiddler$" emptyValue=<<currentTiddler>> >
<$button tag=div to=<<tiddler>> tooltip="Click to open source"><$transclude tiddler=<<tiddler>>/></$button>
</$set>
\end

<<content-link test>>

It could be extended to use another or any field like the last nested fieldnames, eg an excerpt field. Or get smarter and open the target for edit with ctrl-click, or open below (without navigating to it, with shift-click.

Thanks for the inspiration

2 Likes

Custom transclusion is what I have used in kookma Utility plugin! See

https://kookma.github.io/TW-Utility/#Utility%20Tutorial

It has small macros to trasclude and link to: code, rendered, fields, …

This is a clever solution as it uses several else statements.

I got used to

{{{ [<tiddler>get[$field$]else{!!caption}]  ~[<tiddler>get[title]] }}}

Mohammad,

Until this example with the <tiddler> I would have used [all[current]

I actually suspect there may even be a cleaner way to deal with a cascade of values.

Be right Back - I have an idea!

1 Like

Yes, This was my idea!

Checkout this filtered transclusion,

{{{ [{!!descriptions}] [{!!caption}] [{!!title}] +[!is[blank]first[]] }}}

The nice thing is when using fields the {!!fieldname} implies the current tiddler, making the code even simpler and somewhat more readable and self documenting.

I was forced to use the !is[blank] but possibly trim could also do it. Perhaps if we had firstnonblank[] operator.

{{{ [{!!descriptions}] [{!!caption}] [{!!title}] +[firstnonblank[]] }}}

\define linkify(tiddler field:"caption")
<$set name=currentTiddler value="$tiddler$" emptyValue=<<currentTiddler>> >
<$link >
  <$text text={{{ [{!!descriptions}] [{!!caption}] [{!!title}] +[!is[blank]first[]] }}}/>
</$link>
</$set>
\end

<<linkify test>>
4 Likes

Thank you Tones! Nice tricks!

This thread has moved to #how-to category! Thanks Mario!
So all tips and tricks will be available to interested users!

I thought I would share a small modification I made to this, the linkify macro’s been pretty handy

\define Linkify(field:'title', value, text)
<$list filter="[$field$[$value$]]">
<$link>
<$reveal type="nomatch" state="$text$" text="$text$">$text$</$reveal>
<$reveal type="match" state="$text$" text="$text$"><$text text="$value$"/></$reveal>
</$link>
</$list>
\end

<<Linkify initials JR Jeremy>>

The changes let you pick a specific field, and add additional text if you want, or to just show as the field value.

So if you have a tiddler titled “JeremyRuston” with a initials of “JR”, you could put <<Linkify initials JR Jeremy>> and it will create a link of “Jeremy” to that tiddler. If you just wanna show their initials, you can just do <<Linkify initials JR>> and there ya have it.

I found it pretty handy for super long tiddler names. something like <<Linkify initials JR {{!!title}}>> would allow you to show the full title, but only need to type out whatever the field value you choose is.