How to avoid generating a link to a tiddler

Hi,

as an old assembler developer I am sometimes struggling with the number of the right brackets.
Please help me to avoid generating a link.

I want to show the caption field somewhere in my text and I am using this code

{{{ [get[caption]] }}}

I have the caption field now but also it is a link to this what I don’t want to have.

Thx in advance
Stefan

<$text text={{{ [get[caption]] }}} />

Important note: when a filter STARTS with the get[...] filter operator, it has an implied all[] preceding it.

As a result,

{{{ [get[caption]] }}}

will output the captions for ALL tiddlers in your TiddlyWiki.

In addition, when used as a widget parameter value (as in the response provided by @saqimtiaz)

<$text text={{{ [get[caption]] }}} />

it will output the caption of the FIRST tiddler it finds.

To get the result I suspect you want, you will need to specify which tiddler you want the caption from using something like this:

<$text text={{{ [<currentTiddler>get[caption]] }}} />

-e

1 Like

IMO you could use the <<toc-caption>> macro, which is part of the $:/core/macros/toc

At the time of writing, it is implemented like this:

\define toc-caption()
\whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left">
<$set name="tv-wikilinks" value="no">
  <$transclude field="caption">
    <$view field="title"/>
  </$transclude>
</$set>
</span>
\end

So, it disables automatic CamelCase links, and it uses the tiddler title, if the caption is missing.
There are some additional CSS classes, which only matters, if you did mess around with them.

If you do not like the extra classes, you could create your own little macro without the “outer” SPAN.

-m

This is something that the new function definitions excel at, helping us avoid the verbose text widget.

\function get.caption() [get[caption]]

then simple use <<get.caption>> in your text, it will not be a link.

  • In some cases you may need to add +[join[ ]] at the end of your function, so you return more than the first title.
  • I like to write [all[current]get[caption]] to make it read clearly what you are doing.
  • There may be cases where the caption contains wikitext markup, and it may need to be handled differently

Maybe a very silly question.

Why not use {{ !!caption }} ? That’s a pretty concise way of saying show me the value of the caption field for the current tiddler right “here”. And without any link format.

2 Likes

You are right that is much more elegant.

I was not aware of such a possibility.

Thx

I go Coco for TW’s Transclusion excellence.

The important reading about simple Transclusion in “Wiki Text”: https://tiddlywiki.com/#Transclusion%20in%20WikiText

By the way, {{ MyTiddler }} is the short form of the longer equivalent: {{ MyTiddler!!text }}

I did not notice that little nugget in the documentation.

Read through the Transclusion Basic Usage tiddler for a good start on transclusions with links at bottom for more.

I will also add, if you are not using a widget such as $text $transclude … and only using braces such as {{{ << {{ {{!! you are more likely to be using a short form which is translated into the long form before rendering into HTML to display the result.

  • Not all functionality is available in short forms but it is getting close
  • As soon as things get confusing it can be helpful to expand it to the long form
  • As in my function example above we are choosing a short form but one that already produces the result we want, ie not requiring the $text widget to ensure no link appears.
  • There are also ways to alter default behaviour

Sample code.

{{{ [all[current]get[caption]] }}}

{{!!caption}}

<$transclude $field=caption/>