Reordering Tags

198 views
Skip to first unread message

magey kun

unread,
Nov 10, 2019, 11:42:39 PM11/10/19
to TiddlyWiki
Per: https://tiddlywiki.com/static/Tagging.html
 
Change the order in which tags are listed
By default, tagged tiddlers are listed in alphabetical order. 
If you want any other order, add a list field to the tag tiddler, and set its value to be a list of the tiddlers in that order.

I'm relatively new to using Tiddlywiki, and the explanation provided here hasn't been sufficient for me to figure out how to get tags to appear in a desired order.  Where is the "tag tiddler" I need to edit (is this a shadow or system tiddler somewhere?), and what syntax is expected for this list?

For example, if I have "Example Tiddler" with tags "A" "B" "C", what do I actually have to do to get the tag pills to appear in order "B" "A" "C"?

Thanks for any assistance.

TonyM

unread,
Nov 11, 2019, 12:52:40 AM11/11/19
to TiddlyWiki
mageykun

Take a "tagename" you have used and add it to this macro instead or tagname

<<tag "tagname">>

This will create a tag pill, you can click this and see the tiddlers with the tag, or open a tiddler by the name of the tag.

If you have more than one tiddler tagged in the tag pill popup you can drag and drop the list order. This does the same as the manual instruction to create a list field.

The list field will be created inside the tagname tiddler.

But any tag pill in the tag manager also allows this ordering.

Regards
Tony

Eric Shulman

unread,
Nov 11, 2019, 1:01:51 AM11/11/19
to TiddlyWiki
The documentation refers to the order of "tagged tiddlers"... not the order of the tags themselves.  Thus, if you have three tiddlers, "foo", "bar", and "baz", all tagged with "A", you can create a tiddler named "A", in which you define a field named "list", with a value of "baz foo bar".  Then, if you view any of those tiddlers and click on the tag pill labeled "A", you will see a droplist showing the *tagged* tiddlers in the order, "baz, foo, bar"

Of course, this is not what you are asking for.

The display of the tags themselves is defined here: $:/core/ui/ViewTemplate/tags, which contains:
<$reveal type="nomatch" stateTitle=<<folded-state>> text="hide" tag="div" retain="yes" animate="yes">
<div class="tc-tags-wrapper"><$list filter="[all[current]tags[]sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/></div>
</$reveal>

As you can see, the $list filter definition used here includes "sort[title]".  Thus, the names of the tags are always sorted alphabetically.

To apply a custom sort order to the tag names, you will need to modify $:/core/ui/ViewTemplate/tags, like this:
<$reveal type="nomatch" stateTitle=<<folded-state>> text="hide" tag="div" retain="yes" animate="yes">
<div class="tc-tags-wrapper">
   <$list filter="[all[current]tags[]] +[enlist{MyTagOrder}]" template="$:/core/ui/TagTemplate" storyview="pop"/>
   <$list filter="[all[current]tags[]] -[enlist{MyTagOrder}] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>
</div>
</$reveal>

Then, define a tiddler named "MyTagOrder", containing the names of the tags you want to have listed in a specific order.

For example, suppose you tag a tiddler with the following tags:
foo bar baz A B C
Then, using the standard tag display code, the tags would appear, sorted by title, as:
A B bar baz C foo

and, if you define MyTagOrder containing:
foo bar
then, using the modified tag display code, the tags would appear this would appear as:
foo bar A B baz C

Q.E.D.

enjoy,
-e
Eric Shulman
TiddlyTools: "Small Tools for Big Ideas!" (tm) http://tiddlytools.github.io/
InsideTiddlyWiki: The Missing Manuals http://insidetiddlywiki.tiddlyspot.com/

HansWobbe

unread,
Nov 11, 2019, 9:33:23 AM11/11/19
to tiddl...@googlegroups.com
Eric:

No matter how much I learn about TiddlyWiki, I always find myself re-membering, re-learning, re-enjoying your informative posts.

As a result, I almost find myself wanting to go back through the historical post and apply tags, if only to ensure I am maximize my own learning.

Best regards,
Hans

P.S.:
  • I've added the tags a_tag and z_tag to test their value as a potential index.
  • It should be possible to extend this test to create a PositionalNotation that helps find existing content.
  1. "z_tag" (nonWord) testing started, now that Tagging is restricted to Moderators.
  2. ...
^

mageykun

unread,
Nov 11, 2019, 12:30:43 PM11/11/19
to TiddlyWiki
Thank you very much Eric, that is exactly what I was looking for, and it works like a charm.

mageykun

unread,
Nov 11, 2019, 12:53:14 PM11/11/19
to TiddlyWiki
Hmm. Actually, there is one small bug: this code does sort the tags in the specified order, but the tags listed in "MyTagOrder" appear on all Tiddlers, even those without those tags.

So for example, if the contents of "MyTagOrder" are "foo bar", every Tiddler gets "foo" and "bar" tag pills displayed, even if the Tiddler lacks these tags.

Eric Shulman

unread,
Nov 11, 2019, 9:55:38 PM11/11/19
to TiddlyWiki
On Monday, November 11, 2019 at 9:53:14 AM UTC-8, mageykun wrote:
Hmm.  Actually, there is one small bug: this code does sort the tags in the specified order, but the tags listed in "MyTagOrder" appear on all Tiddlers, even those without those tags.

So for example, if the contents of "MyTagOrder" are "foo bar", every Tiddler gets "foo" and "bar" tag pills displayed, even if the Tiddler lacks these tags.


ARGH!  The problem is due to the fact that the "enlist[]" filter operator is a https://tiddlywiki.com/#Selection%20Constructors

I'm not sure how to solve this problem, but I'm thinking about it... I'll let you know if I find a solution.

-e

mageykun

unread,
Nov 13, 2019, 9:47:12 AM11/13/19
to TiddlyWiki
Well, at the very least, I now know $:/core/ui/ViewTemplate/tag is what needs to be altered.


One possible workaround:
if filtering based off a centralized list doesn't work, could I just alter the sort instead?

Say, define a new field "tagpriority" and assign a value in this field for the Tiddler of every tag (ie, go to Tiddlers foo and bar then add the field tagpriority with a value of 1 and 2 respectively). Then instead of filtering by enlist[], filter within [all[current]tags[]] for the presence of this field, and then sort by the tagpriority value. (Followed by a second alphabetical list of all current tags that lack that field).

It would be less elegant to have to assign values to each tag one by one instead of relying on a central list, but it circumvents needing to rely on enlist[].

Second (sketchier) idea for a workaround:

As far as I can tell, the main issue here is


filter="[all[current]tags[]] +[enlist{MyTagOrder}]"

DOESN'T return "all current tags that also appear in MyTagOrder" as one might expect (it always returns the contents of MyTagOrder).

BUT


filter="[all[current]tags[]] -[enlist{MyTagOrder}]"

does return "all current tags, discounting those that appear in MyTagOrder", as one would expect.

So then could the solution could become to run

<$list filter="[all[current]tags[]] -[enlist{MyTagOrder}] />
and then save this list to a variable instead of printing the output. Then

<$list filter="[all[current]tags[]] -[enlist<VARIABLENAME>]" template="$:/core/ui/TagTemplate" storyview="pop"/>
which should return all current tags, minus those in the variable, and the variable contains all current tags minus those in MyTagOrder.

And so instead of relying on the combination of the + operator and enlist[] filter, we rely on the - operator twice. (Of course, I have no idea if one can use variables and lists this way!)

Eric Shulman

unread,
Nov 13, 2019, 11:08:51 AM11/13/19
to TiddlyWiki
On Wednesday, November 13, 2019 at 6:47:12 AM UTC-8, mageykun wrote:

As far as I can tell, the main issue here is

filter="[all[current]tags[]] +[enlist{MyTagOrder}]"
DOESN'T return "all current tags that also appear in MyTagOrder" as one might expect (it always returns the contents of MyTagOrder).

BUT
filter="[all[current]tags[]] -[enlist{MyTagOrder}]"
does return "all current tags, discounting those that appear in MyTagOrder", as one would expect.

So then could the solution could become to run

<$list filter="[all[current]tags[]] -[enlist{MyTagOrder}] />
and then save this list to a variable instead of printing the output.  Then

<$list filter="[all[current]tags[]] -[enlist<VARIABLENAME>]" template="$:/core/ui/TagTemplate" storyview="pop"/>
which should return all current tags, minus those in the variable, and the variable contains all current tags minus those in MyTagOrder.

And so instead of relying on the combination of the + operator and enlist[] filter, we rely on the - operator twice.  (Of course, I have no idea if one can use variables and lists this way!)


I'm VERY impressed with your logical thinking!

Change $:/core/ui/ViewTemplate/tags like this:
<$reveal type="nomatch" stateTitle=<<folded-state>> text="hide" tag="div" retain="yes" animate="yes">
<div class="tc-tags-wrapper">

   <$set name="OtherTags" filter="[all[current]tags[]] -[enlist{FavoriteTags}]">
   <$list filter="[all[current]tags[]] -[enlist
<OtherTags>] +[reverse[]]" template="$:/core/ui/TagTemplate" storyview="pop"/>
   <$list filter="[all[current]tags[]] -[enlist{FavoriteTags}] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>
   </$set>
</div>
</$reveal>

Then, as before, create [[FavoriteTags]], containing:
foo bar D

and, to test, create [[ATestTiddler]], tagged with:
A B C foo bar baz

This time, it works as desired, with the resulting tag display for [[ATestTiddler]] showing:
foo bar A B baz C
and *without* showing your favorite tags on ALL other tiddlers.

Notes:
* You need to use +[reverse[]] in the first $list filter because "[all[current]tags[]]" *dominantly appends* the listed tags, one at a time, which implicitly reverses the order you specify... the +[reverse[]] puts them back in the right order.
* I added "D" to the FavoriteTags, just to be sure that it does NOT appear anywhere (since nothing is actually tagged with "D")

Of course, I only did this one quick test and I just woke up a little while ago, so I may have missed some odd fringe case (but I don't think so).  Give this a try on your tiddlers, and let me know if anything comes out wrong!

enjoy,
-e






 

mageykun

unread,
Nov 14, 2019, 12:34:49 PM11/14/19
to TiddlyWiki
Ooh. It's so close, but I found an edge case.

If the contents of [[FavoriteTags]] are not in alphabetical order, it forces them to be so in the tag display.

So for instance, if the contents of [[FavoriteTags]] is:
"Foo Baz Bar D"

Then the tag display for [[ATestTiddler]] is
"Foo Bar Baz A B C"
NOT
"Foo Baz Bar A B C"
as desired.

So this lets you put a certain group of tags ahead of all other tags, but doesn't let you define an arbitrarily order for that group. Each sub-group of tags are still alphabetical.

Not sure what the easy fix is there- instead of the [reverse[]], could that list contain a sort based on [[FavoriteTags]]?

The clunkier solution could be to break [[FavoriteTags]] up into multiple Tiddlers (start a new Tiddler every time the next tag isn't alphabetical), and make the process iterative (so you filter out and list your "first class" tags in alphabetical order, then the "second class" tags, and so on, until finally listed the un-favored tags last).

Thanks again for the assistance so far bridging the knowledge gap, it's much appreciated.

Eric Shulman

unread,
Nov 14, 2019, 2:13:25 PM11/14/19
to TiddlyWiki
On Thursday, November 14, 2019 at 9:34:49 AM UTC-8, mageykun wrote:
Ooh. It's so close, but I found an edge case.

If the contents of [[FavoriteTags]] are not in alphabetical order, it forces them to be so in the tag display.


I think I've got a solution!  See if this makes sense to you:

1) Create [[ATestTiddler]], tagged with "A B Bar Baz C foo"
2) Copy-and-paste the following experiment into the body of [[ATestTiddler]]
''THIS IS THE STANDARD TAG DISPLAY:'' All tags, sorted alphabetically<br>
``<$list filter="[all[current]tags[]] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>``<br>
<$list filter="[all[current]tags[]] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>

''ALL FAVORITE TAGS:'' defined in text field of FavoriteTags tiddler<br>
``<$list filter="[enlist{FavoriteTags}]" template="$:/core/ui/TagTemplate" storyview="pop"/>``<br>
<$list filter="[enlist{FavoriteTags}]" template="$:/core/ui/TagTemplate" storyview="pop"/>

''FAVORITE TAGS NOT TAGGING THIS TIDDLER:''<br>
``<$list filter="[enlist{FavoriteTags}] -[all[current]tags[]]" template="$:/core/ui/TagTemplate" storyview="pop"/>``<br>
<$list filter="[enlist{FavoriteTags}] -[all[current]tags[]]" template="$:/core/ui/TagTemplate" storyview="pop"/>

''THIS IS PART ONE:'' FavoriteTags excluding those not tagging this tiddler<br>
``<$set name="nottagged" filter="[enlist{FavoriteTags}] -[all[current]tags[]]">
<$list filter="[enlist{FavoriteTags}] -[enlist<nottagged>]" template="$:/core/ui/TagTemplate" storyview="pop"/>
</$set>``<br>
<$set name="nottagged" filter="[enlist{FavoriteTags}] -[all[current]tags[]]">
<$list filter="[enlist{FavoriteTags}] -[enlist<nottagged>]" template="$:/core/ui/TagTemplate" storyview="pop"/>
</$set>

''THIS IS PART TWO:'' All Tags excluding FavoriteTags, sorted alphabetically<br>
``<$list filter="[all[current]tags[]] -[enlist{FavoriteTags}] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>``<br>
<$list filter="[all[current]tags[]] -[enlist{FavoriteTags}] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>

''THIS IS THE DESIRED RESULT:'' Part one followed by part two<br>
``<$set name="nottagged" filter="[enlist{FavoriteTags}] -[all[current]tags[]]">
<$list filter="[enlist{FavoriteTags}] -[enlist<nottagged>]" template="$:/core/ui/TagTemplate" storyview="pop"/>
<$list filter="[all[current]tags[]] -[enlist{FavoriteTags}] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>
</$set>``<br>
<$set name="nottagged" filter="[enlist{FavoriteTags}] -[all[current]tags[]]">
<$list filter="[enlist{FavoriteTags}] -[enlist<nottagged>]" template="$:/core/ui/TagTemplate" storyview="pop"/>
<$list filter="[all[current]tags[]] -[enlist{FavoriteTags}] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>
</$set>

To test:
3) Check the results shown in [[ATestTiddler]] are as expected... i.e., that the last experimental output is the desired tag display.

To implement:
4) Paste the final code into $:/core/ui/ViewTemplate/tags:
<$reveal type="nomatch" stateTitle=<<folded-state>> text="hide" tag="div" retain="yes" animate="yes">
<div class="tc-tags-wrapper">

   <$set name="nottagged" filter="[enlist{FavoriteTags}] -[all[current]tags[]]">
   <$list filter="[enlist{FavoriteTags}] -[enlist
<nottagged>]" template="$:/core/ui/TagTemplate" storyview="pop"/>

   <$list filter="[all[current]tags[]] -[enlist{FavoriteTags}] +[sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/>
   </$set>
</div>
</$reveal>

Let me know how it goes...

-e

mageykun

unread,
Nov 14, 2019, 8:32:02 PM11/14/19
to TiddlyWiki
Aha, perfect!  That does indeed do it.

Thank you for sticking with this, you've been a great help.
Reply all
Reply to author
Forward
0 new messages