Any way to manually sort tags in a tiddler?

I would like to display the tags in a tiddler (those shown under the tiddler name) in a custom order. For example I want to have the tags ‘Inbox’ ‘todo’ ‘Do’ ‘Tools’ to be shown in this order rather than the existing order which is alphabetic.

Neither Perplexity nor Copilot provided me with a correct answer. Perhaps I need help from a human being to get the answer (if there is one)!

Not yet. There is a draft PR at GitHub. But that’s not finished at the moment.

1 Like

Give this a try:

First, edit the $:/core/ui/ViewTemplate/tags TWCore shadow tiddler and replace this:

filter="[all[current]tags[]sort[title]]"

with

filter="[all[current]tags[]sort[title]sortby{$:/config/TagDisplayOrder}]"

Then, create $:/config/TagDisplayOrder, and enter your list of tags into the text field in the order you want:

Inbox todo Do Tools

Notes:

  • if a tag contains spaces, you will need to enclose it within doubled square brackets.
  • any tags not listed in $:/config/TagDisplayOrder will be displayed in the usual alphabetic order, BEFORE any of the listed tags.
  • if $:/config/TagDisplayOrder doesn’t exist, or is empty, then the all of the tags will display in the usual alphabetic order.

Also, if you want your specified tags to be shown FIRST (instead of following the unlisted tags), you can use two $list widgets in $:/core/ui/ViewTemplate/tags, like this:

<$list filter="[all[current]tags[]sort[title]sortby{$:/config/TagDisplayOrder}]
   :filter[[$:/config/TagDisplayOrder]contains:text<currentTiddler>]"
   template="$:/core/ui/TagTemplate" storyview="pop"/>
<$list filter="[all[current]tags[]sort[title]] -[enlist{$:/config/TagDisplayOrder}]"
   template="$:/core/ui/TagTemplate" storyview="pop"/>

The first $list widget will only show tags that are also contained in $:/config/TagDisplayOrder
Then, the second $list widget shows all other tags, excluding those contained in $:/config/TagDisplayOrder

enjoy,
-e

5 Likes

Continuing with @EricShulman’s suggestion, you can also edit $:/core/ui/EditTemplate/tags shadow tiddler to order tags when adding new tags.

<$list filter="[list[!!$tagField$]sort[title]sortby{$:/config/TagDisplayOrder}]" storyview="pop">

PS: I set color field for each type of tags (e.g. colleague, domain, place), then add sort[color] after sort[title] to automatically sort each type of tags.

1 Like

I was going to try the suggested solutions but there was a rather alarming message stating

You are about to edit a ShadowTiddler. Any changes will override the default system making future upgrades non-trivial. Are you sure you want to edit “$:/core/ui/ViewTemplate/tags”?

I decided to avoid doing anything that might destabilize my wiki. I’ve spent some time synchronizing my tiddlers to my files etc. on the PC, plus I’m using @EricShulman 's excellent Calendar, alarms and timers system for my daily routines.

Perhaps I should wait for a “stable” solution. Ideally I would like a drag and drop solution where I could manually reorder the tags on a specific tiddler at a time by moving the relevant pills.

You should not let that concern you. It’s just reminding you by way of a warning, you are about over-shadow a shadow tiddler. You’re “displacing” it, not deleting it. Some of us “displace” shadow tiddlers all the time.

And besides, anytime you want to revert to the TiddlyWiki-supplied shadow tiddler, just rename your over-shadow tiddler. As if by magic, the core version will return ready to take on its job once again.

In fact, “You are about to edit a ShadowTiddler” is misleading. You are not editing a shadow tiddler. Rather, you’re providing an “over-shadowing” tiddler.

2 Likes

Editing a shadow tiddler creates an “ordinary” tiddler with the same name which overrides the original shadow definition, but does not overwrite or remove that definition. To restore the original shadow definition, you simply delete (or rename) the overriding ordinary tiddler, which allows the original version to “re-emerge from the shadows” (hence the name!)

The “about to edit a ShadowTiddler” warning is generic when ANY shadow tiddler is about to be modified. If you subsequently upgrade the TWCore (i.e., using the TiddlyWiki Upgrader), ALL shadow tiddlers will still be upgraded at that time. However, any shadows that you have edited are still overridden by your previous changes, so any improvements to those particular shadow tiddlers won’t be applied.

For many shadow tiddlers, this is not a problem, unless you have changed a shadow tiddler that contains javascript code (which also requires a save-and-reload before those changes are applied). As a general rule you should always save a backup copy of your TiddlyWiki before making any changes, so if something does go wrong, you can easily revert to your most recent working version.

Small changes to “ui” shadow tiddlers are a normal part of customizing your TiddlyWiki to suit your needs. The change to $:/core/ui/ViewTemplate/tags that I suggested is actually VERY safe, as it extends the default TWCore behavior, but doesn’t alter that default behavior if the $:/config/TagDisplayOrder tiddler is empty or not present.

Go ahead and give it a try.

-e

5 Likes

Thank you for the explanation. It’s very clear and useful to know.

I like the idea to sort tags by color, but in my case the tag’s colors are defined by the cascade mechanism.
Any idea on how to proceed in this case ?

There is a draft PR at Github, Colour handling improvements by Jermolene · Pull Request #8702 · TiddlyWiki/TiddlyWiki5 · GitHub, which will give us some TW functions with which we should be able to create TW filters that may allow us to “kind of sort” by colour.

But colours are not really sortable even if we have better low level functions. So it will be tricky, especially if your colours are created using the cascade mechanism.