How to get List-links sorted?

Hello Experts,

I want to get my list-links sorted but I fail.
Any help is welcome.

<<list-links "[<currentTiddler>backlinks[]] [<currentTiddler>backtransclude[]]" "sort[title]">>

Returns it not alphabetically ordered.
Additional how change the filter that the caption (if available) of the tiddlers will be listed?

Thx in advance for help
Stefan

Hi

Try this:

<<list-links "[<currentTiddler>backlinks[]] [<currentTiddler>backtranscludes[]] +[sort[]]">>

list-links macro does this by default.

Fred

1 Like

In examples from https://tiddlywiki.com/#list-links%20Macro%20(Examples) the filter: parameter name is explicitly specified. In this thread the filter is passed as positional rather than named parameter. Is it because when parameters are passed positionally, the macro handles them in the order they are specified in the macro definition?

As far as I can tell, yes.

Official documentation for macro calls doesn’t explicitly state it, but what I understand is parameter names can be omitted and then declaration position is used for name/value mapping.

So in @stefan_from_germany example code, the second parameter value "sort[title]" would be mapped to type parameter.
This can be seen in “widget tree” preview mode:

Fred

2 Likes

Off-topic warning!

Even though I don’t know why anyone would want to do this, it’s possible to override positional order by using indices instead of parameter names like this:

<<list-links 1:"ol" 0:"[[A]] [[B]]">>

Result:

  1. A
  2. B

Fred

1 Like

It did not know this, I always explicitly name the parameters, It is called: using named parameters.

<<list-links type:"ol" filter:"[tag[Learning]]">>

I didn’t know either, I just discovered it today in “parse tree” and “widget tree” outputs while answering this thread… Serendipity…

Fred

Hi @tw-FRed,

One last topic I need to ask here.
The list will be sorted by the title but shown will be the caption?
So far so good. Bu If the Title is alphabetically sorted before the caption it is not sorted.

I reduced my example here a little bit:

Tiddler B : [[Tiddler_A]]

Tiddler_C with caption “ABC” : {{Tiddler_A}}

Tidler_A : <<list-links “[backlinks[]] [backtranscludes[]] +[sort[]]”>>

And the result in Tiddler_A is:

  • Tiddler_B
  • ABC

Because the title are sorted not and the caption (if available).

Looks strange :grinning:

Stefan

Hi @stefan_from_germany

If in your real use-case some tiddlers have a caption and some don’t, I don’t know how to solve the sorting problem. Maybe it could be done in a <$list> widget instead of a <<list-links>> macro, but even then I wouldn’t know how to do it… You’d have to remember the original tiddler title, replace it by caption when available, then sort, and build the links… quite involved! Maybe by building a compound string like caption-or-title|title, then sorting, then splitting back to get the tiddler title…

Anyway, if every tiddler has a caption though, it’s easy:

<<list-links “[backlinks[]] [backtranscludes[]] +[sort[caption]]”>>

Hope this helps,

Fred

Edit: @stefan_from_germany see @EricShulman answer below, his solution is perfect!

Challenge accepted! :grin:

Paste this code at the beginning of Tiddler_A text:

\function fn.compose() [{!!caption}!is[blank]else{!!title}] "|" =[{!!title}] +[join[]]
\function fn.caption() [<compound>split[|]first[]]
\function fn.title() [<compound>split[|]last[]]

<ul><$list
  filter="[<currentTiddler>backlinks[]][<currentTiddler>backtranscludes[]] :map[fn.compose[]] +[sort[]]"
  variable="compound"
>
<li><$link to=<<fn.title>>><<fn.caption>></$link></li>
</$list></ul>

Fred

You can use the :sort[...] filter run, which would permit you to sort by either caption or title, like this:

<<list-links "[backlinks[]] [backtranscludes[]] :sort[{!!caption}!match[]else{!!title}]">>

The advantage of the :sort[...] filter run is that it uses a separate filter to determine the value to sort by, without changing the current title value in the process.

See https://tiddlywiki.com/#Sort%20Filter%20Run%20Prefix for more info

-e

4 Likes

Thank you @tw-FRed and @EricShulman,

Thank you for your support.

I created a tiddler and tagged it with $:/tags/ViewTemplate.
Now I get the information below each tiddler what is very helpful in such a complex wiki like mine.

created: 20241206114923250
creator: stefan_from_germany
modified: 20241216083126496
modifier: stefan_from_germany
tags: $:/tags/ViewTemplate
title: $:/List_of_Linked_Tiddlers

<hr>
<b>
This Information is linked with these chapters also:
</b>
<<list-links "[<currentTiddler>backlinks[]] [<currentTiddler>backtranscludes[]] :sort[{!!caption}!match[]else{!!title}]">>
<hr>

Stefan