A Filter Question: Sort by Caption or Title If Caption Is Not Existed

I have a list of tiddlers, simply list them by list-links like below

<<list-links filter:"[tag[Learning]sort[caption]]">>

but some of tiddlers have no caption or their caption are empty, what is the one go filter expression (may have several runs and/or steps) to sort them by caption/title?

I think I found a solution

<<list-links "[tag[Learning]] :sort:alphanumeric[get[caption]else{!!title}]" field:"title">>

The shortcut transclusion helped here! (Seems :sort:alphanumeric[{!!caption}else{!!title}], but I prefer get over {!!} in script.

3 Likes

You can also do this with sortsub.

Riffing on the last example in https://tiddlywiki.com/#sortsub%20Operator%20(Examples), I wrote this version, which ends up fairly similar to yours, but with the sorter extracted and thus reusable:

<$let mysort="[get[caption]else{!!title}]">
<<list-links "[tag[Book]sortsub<mysort>]" field:"title">>
</$let>

To see this in action, you can drag this to a wiki and look at “Sort by caption or title”:

SortByCaptionOrTitle.json (1.4 KB)

3 Likes

Works great! Thank you, Scott!
Your sortsub gives more flexibility, as any complex expression can be implemented!

1 Like