Sort tabs list by created date

How would I get the following tabs list to sort by reverse chronological created date & have the default tiddler always be the most recent one? Thank you.

<<tabs tabsList:"[tag[TAG]]" default:"TIDDLER ">>

Since the tabsList param uses filter syntax, you can easily sort it using "[tag[TAG]!sort[created]]"

To select the most recent tag as the default take slightly more effort. Instead of using the shortcut <<tabs ...>> macro (which only accepts literal parameter values), you will need to use the <$macrocall ...> widget so you can set the default parameter to a computed value using a “filtered transclusion”, like this:

<$macrocall $name="tabs"
   tabsList="[tag[TAG]!sort[created]]"
   default={{{ [tag[TAG]!sort[created]first[]] }}}/>

Note that, when using filtered transclusion to set a widget parameter, the parameter value will automatically use the first item returned by the filter, so we can actually omit the first[] filter operator, and {{{ [tag[TAG]!sort[created]] }}} will be sufficient for getting that first item value.

Also, to avoid repeating the filter syntax twice, you could use a $set widget to first get the list of tagged items, and then apply that result to the tabs macro parameters, like this:

<$set name="myTags" filter="[tag[TAG]!sort[created]]">
<$macrocall $name="tabs" tabsList=<<myTags>> default={{{ [enlist<myTags>] }}}/>
  • The $set widget “captures” the results of the filter as a space-separated bracketed list of titles. This makes the value of the myTags variable suitable for use as the parameter value of the tabsList parameter.
  • Then, for the default parameter value, the {{{ [enlist<myTags>] }}} filtered transclusion syntax breaks the list into individual titles and, as before, only the FIRST item from that filtered transclusion is used as the widget parameter value.

enjoy,
-e

1 Like

Awesome, thank you! :grin: