How to sort the tag dropdown based on a filter or variable?

I’d like to sort the tags that appear in the dropdown based on the criteria I select.

What I wanted to do was, under the Project tag, to first show active projects (no Archive tag), then show archived projects at the end. My first approach was to try using variables in the list field. For example:

<<active-projects>> <<archived-projects>>

I tried several variations of this, including using a <<project-sort>> variable formatted as a space-separated list, but it didn’t work.

My second approach was to edit $:/core/ui/TagTemplate to try to add a sortby subfilter to the tag dropdown that referenced a tag-sort field. So it would look something like this:

<$macrocall $name="list-tagged-draggable" tag=<<currentTiddler>> subFilter="sortby{!!tag-sort}"/>

However, this didn’t work if the tag-sort field contained variables, only if it had the plain text list (which would be no different than using the list field and sorting manually).

After playing around with things I gave up and just changed the relevant section of $:/core/ui/TagTemplate so tiddlers tagging Archive always appear at the end of the list, like so:

<$macrocall $name="list-tagged-draggable" tag=<<currentTiddler>> subFilter="!tag[Archive]"/>
<$macrocall $name="list-tagged-draggable" tag=<<currentTiddler>> subFilter="tag[Archive]"/>

But, I wonder if there’s a way to do what I was trying, so I can have a more reusable mechanism for programmatically sorting the tag dropdown list?

Keep in mind the tag dropdown is an essential tool throughout a wiki so while customisation for a particular tag is a good idea caution is warented. Here are few options to concider. I will share more once on my desktop.

There is a tag for adding items to the tags dropdown.
Use this and add additional lists to the drop down with the filters you want.

Perhaps store the alternate filters in the tag tiddler itself.

Consider making a pho tag and drop down out of a button and use this instead.

More soon…

The tag to use to add items to the drop down is $:/tags/TagDropdown

See my bundle of tag down related tools in this package not also the introduction of an additional viewToolbar on which an icon appears if the current tiddler is tagging others.

reimagin-tags.json (9.5 KB)

So in particular perhaps you could clone $:/PSaT/tagging-here/pill and make it appear if the current tiddler has a project tag and put your own filtered active/archived lists there.

I have long planned to provide additional features on the tag pill’s including what I call action tags, tags designed to provide selected actions on the current tiddler via tag pills and the tag. eg a task tag would allow you to tag it done. The work I would do to solve your problem myself would be part of this greater effort. I hope what I have shared gets you to your desired result. Feel free to ask more questions.

If you use the tag dropdown, you already can drag & drop sort the list.

Mario. He wants a structured sort based on tiddler status of archived. But yes that fact should not be missed.

Ah, I believe I understand. So the approach using $:/PSaT/tagging-here/pill is to leave the original tag dropdown as it is, and use my own button/custom tag to display things as I want?

Yes. Since its such a critical component. Just add a conditional list arround the content of the tiddler you use so it only appers when needed as well.

For some of my own wikis I hack the tag dropdown to sort in reverse chronological order. I like the idea of adding a core option for selecting between different sort criteria for the dropdown.

This would be nice but just as you introduced recently with the editor preview the ability to set this on a specific tag would be nice. A filter to support the OT for example.

As we know a tag can be made into a tiddler, I have considered introducing a filter field to that tiddler if desired that if it exists is used instead. In fact the behaviour of tags and the tag pill could be hacked quite a bit via configuration fields on the matching tag tiddler.

eg; The tag pill lists items tagged task not tagged done.

@Jeremy my re-imagine tags package above to see the features I already added to the tag pill in a similar vein.

  • The new with this tag could also be designed to use a tiddler template if it exists (set in the tag tiddler).

Examples may be description or tooltip fields that can explain the tag. Then the tag tiddler itself can be the “go to resource” about the tiddlers it tags. An optional view template for all tag tiddlers can list tiddlers so tagged automatically. Automatically bringing forward the information pertaining to each tag used would be a service to tiddlywiki users. All they need is to open the tag tiddler.

In a parallel the existence of “field tiddlers” (similar to tag tiddlers) which may contain default filters, a goto resource on that fieldname, including view and edit templates for the field. All they need is to open the “field tiddler”.