Link to a tiddler title + extra text?

Hi guys

I wasn’t sure how to describe this in the title.

I am using a list widget to give the output based on a tag.

But I would like the output not only to list a link to that tiddler, but also a link to a potential tiddler whose title has the title of the first tiddler plus (content).

[[Birds]] [[(c)|Birds (content)]]

The first part is easy: <$link/>
I am not sure how to produce the second part. How would I grab the first title, add the word (content), then add it as a link in a list widget output?

I’d probably do something like:

<$link/><$list filter="[{!!title}addsuffix[ (Content)]is[tiddler]]"><$link>(c)</$link></$list>

Give this a try:

<$link to={{{ [{!!title}] [[(Content)]] +[join[ ]] }}}>(c)</$link>

-e

Yeah, I had something similar in my first cut, but I didn’t like that in scenarios where the primary tiddler does not have a related " (Content)" tiddler.

I seem to have read the question slightly differently from Eric and Charlie. It sounded to me that you wanted a second (c) link if that ... (content) tiddler exists.

For that, I would use a procedure, perhaps like this:

\procedure double-link(title)
  <$link to=<<title>> />
  <%if [<title>addsuffix[ (content)]is[tiddler]] %>
    <$link to= {{{ [<title>addsuffix[ (content)]] }}}>(c)</$link>
  <% endif %>
\end

Used like this:

!! Examples:

* `<<double-link Birds>>`: <<double-link Birds>>
* `<<double-link Reptiles>>`: <<double-link Reptiles>>
* `<<double-link Mammals>>`: <<double-link Mammals>>

yielding this:

Examples:

If you want to link to the tiddler whether or not it exists, then you can simply remove the <% if %> and <% endif %> tags.

You can download and drag this onto the main site to see it in action: DoubleLink.json (1.1 KB)

Thanks everyone! Eric’s solution was what I needed, but I will be learning from the other solutions, too!

Apologies, I misunderstood. I thought you only wanted (c) showing if there was a related “… (Content)” tiddler.

:+1:

As did I. But I also went a different way, assuming that this was something that would be used in multiple places, and that a procedure would make it easier to list create both links in a simple manner. (A macro would be similar.)

In any case, I’m glad you found something that works for you!

As an alternative to a macro, you could put either Eric’s solution or Charlie’s in a separate tiddler, e.g.

title: c
text: <$link to={{!!title}} /> <$link to={{{ [{!!title}] [[(Content)]] +[join[ ]] }}}>(c)</$link>

and then use it as a transclusion template: {{Birds||c}}

which would give you

<$link to="Birds" /> <$link to="Birds (Content)">(c)</$link>

You can also use it inside a list: <$list filter="Birds Cats Dogs">{{||c}}</$list> or <$list filter="Birds Cats Dogs" template="c" />

Or as a template in a filtered tranclusion: {{{ Birds Cats Dogs [[Great Apes]] || c }}}

I often prefer transclusion templates for things like this because they can be both more flexible and a little more concise than macros — and they are, by definition, globally available. And, credit where credit’s due, I think I learned this trick from Charlie!

3 Likes