Showing backlinks in one line comma-separated

I’m trying to show the backlinks to the current Tiddler in a comma separated row on all Tiddlers that have backlinks so I did the following in a ViewTemplate:

<$list filter="[all[current]backlinks[]count[]compare:number:gt[0]]" variable=~>
<details>
<summary>Backlinks</summary>
<$list filter="[all[current]backlinks[]!match{!!title}]" counter="counter">
<$link/><$list filter="[<counter-last>compare:string:eq[no]]">, </$list>
</$list>
</details>
</$list>

I was wondering if there is a more elegant solution? I have tried the join[, ] operator but it does not preserve the links correctly.

Not necessarily an improvement, but a slight variation for the giggles:

<$list filter="[<currentTiddler>backlinks[]join[]then<currentTiddler>]" variable="thisTid">
<details>
<summary>Backlinks</summary>
<$list filter="[<thisTid>backlinks[]!match{!!title}]" counter="counter">
<$text text={{{ [<counter>!match[1]then[, ]] }}}/> <$link/>
</$list>
</details>
</$list>
1 Like

I’ve yet to find anything more elegant either, although this is slightly shorter:

<$list filter="[<counter-last>!match[yes]]">, </$list>
1 Like

Old habits die hard.

Slight refactoring to that last one I posted:

<$list filter="[{!!title}backlinks[]nth[1]then{!!title}]">
  <details><summary>Backlinks</summary>
    <$list filter="[{!!title}backlinks[]] -[{!!title}]" counter="counter">
      <$text text={{{ [<counter>!match[1]then[, ]] }}}/> <$link/>
    </$list>
  </details>
</$list>
1 Like

Oh, and since you don’t want self-backlinks:

<$list filter="[{!!title}backlinks[]!match{!!title}nth[1]then{!!title}]">
  <details><summary>Backlinks</summary>
    <$list filter="[{!!title}backlinks[]] -[{!!title}]" counter="counter">
      <$text text={{{ [<counter>!match[1]then[, ]] }}}/> <$link/>
    </$list>
  </details>
</$list>
1 Like

Maybe not an improvement, but it does eliminate two inner nested listwidgets:

<$list filter="[all[current]backlinks[]count[]compare:number:gt[0]]" variable=~>
<details>
<summary>Backlinks</summary>
<$wikify name="out" text={{{ [all[current]backlinks[]!match{!!title}format:titlelist[]]+[join[, ]]" }}}
 output="html"><<out>></$wikify>
</details>
</$list>
1 Like

With the new 5.3.0 features I have a hunch here may be even more elegant ways;

I just started to investigate and first considered if you don’t want the links, just text a simple join is sufficient; However this led to some insight.

  • <$text text={{{ [all[current]backlinks[]] +[join[, ]] }}}/>

However then I remembered, if you display a list of existing titles, with the core Freelinks plugin, they will become active links. So using the same method as above, with freelinks;

<$text text={{{ [tag[TableOfContents]limit[5]] +[join[, ]] }}}/>

Snag_ead91

You could even add a period, with this method.

<$text text={{{ [tag[TableOfContents]limit[5]] +[join[, ]addsuffix[.]] }}}/>

So now using this method the following is also valid;

<$text text=`${ [tag[TableOfContents]limit[5]] +[join[, ]addsuffix[.]] }$`/>

But further research may come up with methods that do not need the freelinks plugin.

  • I will post in this reply if I come up with more.

[Edit 1] Using the Freelinks plugin you can simplify this to;

<$text text=`${ [tag[TableOfContents]limit[5]] +[join[, ]addsuffix[.]] }$`/>

“Filtered transclusions” also work for earlier than 5.3.0

<$text text={{{ [tag[TableOfContents]limit[5]] +[join[, ]addsuffix[.]] }}}/>

Alternatively in 5.3.x you can move it to a custom filter operator

\function comma.list() [join[, ]addsuffix[.]]

<$text text={{{ [tag[TableOfContents]limit[5]] +[comma.list[]] }}}/>
  • I can see moving this into a custom widget, which I have not yet mastered.
<$commalist filter="[all[current]backlinks[]]"/>

A Final example that uses the custom filter operator but not the Freelinks plugin is as follows; but note you can avoid the custom operator to make it compatible with pre TW 5.3.0, you could also move it into a macro.

\function comma.list2() [join[,|]addsuffix[.]]
\function comma.delist2() [all[current]trim[,]trim[.]]

<$list filter="[tag[TableOfContents]limit[5]] +[comma.list2[]] +[split[|]]">
     <$link to={{{ [comma.delist2[]] }}} ><$text text=<<currentTiddler>>/></$link>
</$list>
  • Notice the use of | as a item delimiter

I would vote for the following with the freelinks plugin;

\function comma.list() [join[, ]addsuffix[.]]

<$text text={{{ [tag[TableOfContents]limit[5]] +[comma.list[]] }}}/>

I will stop for now until I get some feedback :nerd_face:

1 Like

You could also style any list using css. See https://amreus.tiddlyhost.com/

3 Likes

Comma list, via CSS: List styles — style items in Listwidget and filtered transclusions

3 Likes

Thank you all for your amazing suggestions! I am learning a lot! Defining a comma list widget would be my favorite.

I agree this is great!!!

1 Like