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.
<<tag "tagname">>
<$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>
<$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>
foo bar baz A B C
A B bar baz C foo
foo bar
foo bar A B baz C
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.
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.
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!)
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!)
<$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>
foo bar D
A B C foo bar baz
foo bar A B baz C
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.
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.
''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>
<$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>