customize order of tag display

177 views
Skip to first unread message

Eric Shulman

unread,
Dec 14, 2020, 1:56:02 AM12/14/20
to TiddlyWiki
Hi all,

Recently, someone asked me if it is possible to apply a custom order to the tags that are displayed on a tiddler, and I came up with a one-line adjustment to the tags ViewTemplate that achieves this:

edit the $:/core/ui/ViewTemplate/tags shadow tiddler and change this line:
<div class="tc-tags-wrapper"><$list filter="[all[current]tags[]sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/></div>
to this:
<div class="tc-tags-wrapper"><$list filter="[all[current]tags[]sort[title]sortby{$:/config/TagsOrder}]" template="$:/core/ui/TagTemplate" storyview="pop"/></div>

The only change is adding "sortby{$:/config/TagsOrder}" to the $list filter.

Then, you can enter tag names into $:/config/TagsOrder, and the display of tags in the ViewTemplate will show those tags in the order specified.

Note that any tags not included in the config tiddler will be listed first, in the default alphanumeric order.  Thus, if the config is empty or non-existent, the current TWCore default behavior is retained.

Also, if there are a lot of tags to be listed, you can auto-generate the initial contents of $:/config/TagsOrder by using the following $button:

<$vars lf="
">
<$set name="taglist" filter="[tags[]trim[]sort[]addsuffix<lf>join[]]">
<$button> make initial ~TagsOrder
   <$action-setfield $tiddler="$:/config/TagsOrder" text=<<taglist>> />
</$button>
(note that the literal newline following lf=" is important)

This outputs all the current tags, one per line, into the text field of $:/config/TagsOrder.  You can then edit the tiddler to add/delete/re-arrange the tags to suit your needs.

enjoy,
-e
T

  

Jan

unread,
Dec 14, 2020, 6:57:42 PM12/14/20
to tiddl...@googlegroups.com
Hi Eric,
very usefull idea. It would be practical to have this in the core bey default, together with a filter which tags to exclude.
Best wishes Jan
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/bedfadea-df81-468b-b852-5e638374671en%40googlegroups.com.

Eric Shulman

unread,
Dec 14, 2020, 8:49:29 PM12/14/20
to TiddlyWiki
On Monday, December 14, 2020 at 3:57:42 PM UTC-8 Jan wrote:
It would be practical to have this in the core by default, together with a filter which tags to exclude.

Indeed!  Both tag display order and hiding specific tags can be done by a minor enhancement to $:/core/ui/ViewTemplate/tags, like this:

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

If the $:/config/TagsOrder and/or $:/config/HideTags tiddlers are empty or missing, then the default TWCore behavior is retained, making this enhancement 100% backward compatible with the current TWCore tag display functionality.

I will open an issue on GitHub, suggesting this change be added.  Of course, with TW5.1.23 so close to release, I expect that this would likely not be added until TW5.1.24 at the earliest.

-e

Sylvain Naudin

unread,
Dec 21, 2020, 2:00:40 PM12/21/20
to TiddlyWiki
+1 for tag config exclusion. I use your solution since you gave me the answer a while ago.

Thanks Eric.

Regards,
Sylvain

TW Tones

unread,
Dec 21, 2020, 4:52:05 PM12/21/20
to TiddlyWiki
Eric,

Thanks for this insight. controlling the tags list is useful. 

  • It does however make me ask if there were a way to use sortby so that the "named" tiddlers were at the beginning and the balance sorted following.

The sortby or another method allows a select set of tiddlers to have their prominence enhanced through sorting, but its not very prominent if they are at the end of the list.

  • I have used your way to define a newline variable before, thanks. But do you know anyway to get it into a global macro?
Regards
Tones

Gavin Gamboa

unread,
Oct 7, 2021, 3:20:17 PMOct 7
to TiddlyWiki
How would we achieve this without altering the core/ui shadow tiddler? Is there a way to make upgrades less of a nightmare and overriding the $:/core/ui/ViewTemplate/tags with our own template ? (I haven't done any deep customization such as this before so sorry ahead of time if it's an obvious answer.)
Message has been deleted

Gavin Gamboa

unread,
Oct 7, 2021, 4:14:08 PMOct 7
to TiddlyWiki
Also I am not sure if I am understanding Eric's suggestion for the tag ordering in the new TagsOrder tiddler:

Then, you can enter tag names into $:/config/TagsOrder, and the display of tags in the ViewTemplate will show those tags in the order specified.

Do we put that in a new list field within the tiddler itself, or do we put our own <$list> widget in the tiddler text body, or do we just list the tags as we would in a list field, but this time in the main text body of the tiddler i.e. Topic [[New Topic]] Fiction [[Non-Fiction]] …… ?

Gavin Gamboa

unread,
Oct 7, 2021, 10:45:43 PMOct 7
to TiddlyWiki

Finally got it to work. The tiddler titled $:/config/TagsOrder (and also tagged $:/config/TagsOrder) had to have each tag incased in [[*]] notation and line separated
[[Tag]]
[[Another Tag]]
[[An Yet Another]]

I don't know why it wouldn't work otherwise. I wish there was a way to set tag precedence rather than have to arrange ALL tiddlers. I did appreciate Eric's button code which pulled in all the tiddlers, though! :)

strikke...@gmail.com

unread,
Oct 8, 2021, 12:55:43 AMOct 8
to TiddlyWiki
You need the [[]] when using two or more words with spaces. [[Another Tag]]

If you did not use [[Another Tag]], you would end up with 2 tags. Another and Tag

Eric Shulman

unread,
Oct 8, 2021, 11:15:13 AMOct 8
to TiddlyWiki
On Thursday, October 7, 2021 at 12:20:17 PM UTC-7 gavin....@gmail.com wrote:
How would we achieve this without altering the core/ui shadow tiddler?

Given the current definition of `$:/core/ui/ViewTemplate/tags`, I don't see any other way to make this change without altering that shadow tiddler.

While this does add some extra steps to the upgrade process, upgrades typically only occur twice a year or so; and, when upgrading, the "status" column will indicate that you that you are overriding a shadow.
After upgrading, you can compare the modified tiddler with the default shadow using these steps:

1) Open $:/AdvancedSearch, Filter tab and select "Overridden shadow tiddlers" from the dropdown next to the input field.
2) Open `$:/core/ui/ViewTemplate/tags` from the search results and click on 'edit' to view the tiddler source
3) In the editor toolbar, enable preview (the closed eye) and from the preview options dropdown (chevron-down, next to the eye), select "differences from shadow (if any)"

The preview panel will now show the differences (if any) between your modified shadow and the newly upgraded shadow (red strikethroughs for removed content, green underlines for added content).
If the only difference is the change you previously made, then you're done.
Otherwise, you will need to delete your modified shadow and then edit the shadow again to hand-merge your changes into the upgraded shadow.

Sure, this is a bit of a hassle, but as I noted above, upgrades only occur twice a year, and most of the time, those changes are to core JS code, rather than UI definitions, so it's probably no more than a few minutes effort.

-e

Eric Shulman

unread,
Oct 8, 2021, 11:21:32 AMOct 8
to TiddlyWiki
On Thursday, October 7, 2021 at 7:45:43 PM UTC-7 gavin....@gmail.com wrote:
Finally got it to work. The tiddler titled $:/config/TagsOrder (and also tagged $:/config/TagsOrder) had to have each tag incased in [[*]] notation and line separated
[[Tag]]
[[Another Tag]]
[[An Yet Another]]

Notes:
* You don't need to tag `$:/config/TagsOrder` with "$:/config/TagsOrder" (unless you want to!)
* Technically, you can enter all the tags on one line using a space-separated list.  I just find that using newline makes it easier to re-order the list since you can select/cut/paste entire lines to move items around.
* The doubled square brackets are only needed for tags that *contain* spaces.
 
...I wish there was a way to set tag precedence rather than have to arrange ALL tiddlers.

How would you go about defining the precedence, if not by listing the tags in the desired order?
 
I did appreciate Eric's button code which pulled in all the tiddlers, though! :)

You're welcome :)

-e 
Reply all
Reply to author
Forward
0 new messages