Removeprefix in the body of a link but not the link itself

I’m having one of my periodic syntax brain-farts.

This properly links to the current tiddler in a table cell:

  <td><$link>{{!!title}}</$link></td>

But all the tiddlers in this table share a common prefix, which I’d like to remove. And I can’t seem to figure out the syntax. This removes the prefix:

  <td><$link>{{{ [{!!title}removeprefix[MyPrefix: ]] }}}</$link></td>

(Side question: is there a simpler version of this?)

But then the link is to the non-existent prefix-removed tiddler. That is, for a tiddler with the title MyPrefix: Some Title, the link is the same as the body, Some Title. The body is what I want, the link is not.

It’s not clear to me why this doesn’t fix it:

  <td><$link to=[{currentTiddler!!title}]>{{{ [{!!title}removeprefix[MyPrefix: ]] }}}</$link></td>

but it has the same behavior as the previous attempt.

I’m sure it’s much simpler than I’m making it, but I’m just not seeing it.

How should I go about this?

{{{ [{!!title}removeprefix[MyPrefix: ]] }}} results in a link, and that is overriding “$link”.

<$text text={{{ [{!!title}removeprefix[MyPrefix: ]] }}}/> will result in plain text, and not override “$link”.

At TiddlyWiki.com, compare:

<$link to="HelloThere">{{{ [[HelloThere]search-replace[There],[]] }}}</$link>

<$link to="HelloThere"><$text text={{{ [[HelloThere]search-replace[There],[]] }}}/></$link>

Yes, that’s it exactly. Thank you. I definitely should have seen that. That’s what I get for taking a week off doing TW development!

Thank you for your help!

It does not much take to miss/overlook/forget what is going on between and as a result of them wee squiggly triplets.

Easy to get flustered by them, but then again, it is kind of fun in a brain-age game kind of way.

BTW, I’m not aware of a more concise way to go about it. I’m not sure a more concise way would so clearly indicate what’s going on.

1 Like

This can be written more compactly as:

<$link to={{!!title}}><$text text={{{ [{!!title}trim[MyPrefix: ]] }}}/></$link>

Note that using the trim[] filter operator instead of removeprefix[] allows the link text to be displayed even if the current tiddler title doesn’t have the "MyPrefix: " leading text.

-e

Thank you. trim is a very useful hint. I’m not sure when and why {currentTiddler} got in there. One of the results of flailing is that everything including the kitchen sink sometimes gets thrown in and not always removed when something finally works.

Oh, never mind. It’s actually the variable <curr> in my actual code, only “simplified” for the post.