How to add in the tag-pill 2 numbers, one that shows the position in the list of the tag, the other that shows the total number of tagged tiddlers

For example, I have 3 tiddlers tagged “document”: Tiddler A, Tiddler B and Tiddler C.

I would like the following to appear in the pill-tag next to the tag name (document):
for Tiddler A: document 1/3
for Tiddler B: document 2/3
for Tiddler C: document 3/3
(the first number is the position in the list field, the second the total number of tiddlers with that tag)

I edited the $:/core/macros/tag tiddler, specifically the “tag-pill-inner” macro like this:

\define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
\whitespace trim
<$vars
	foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">>
	backgroundColor=<<__colour__>>
>
<$element-tag$
	$element-attributes$
	class="tc-tag-label tc-btn-invisible"
	style=<<tag-pill-styles>>
>
	<<__actions__>>
	<$transclude tiddler=<<__icon__>>/>
	<$view tiddler=<<__tag__>> field="title" format="text" />
&nbsp;
<$set name="TiddlerTagged" value={{!!title}}>
<$list filter="[enlist{!!list}] :else[tag{!!title}sort[title]] +[allbefore<TiddlerTagged>count[]add[1]]" variable=Result><<Result>></$list>
/<$count filter="[tag<currentTiddler>]" />
</$set>
</$element-tag$>
\end

More specifically, my changes are theese:

&nbsp;
<$set name="TiddlerTagged" value={{!!title}}>
<$list filter="[enlist{!!list}] :else[tag{!!title}sort[title]] +[allbefore<TiddlerTagged>count[]add[1]]" variable=Result><<Result>></$list>
/
<$count filter="[tag<currentTiddler>]" />
</$set>

I have, however, encountered a couple of difficulties:

  • The first number (e.g. 1/3) is always “1”, I must have done something wrong here:
<$set name="TiddlerTagged" value={{!!title}}>
<$list filter="[enlist{!!list}] :else[tag{!!title}sort[title]] +[allbefore<TiddlerTagged>count[]add[1]]" variable=Result><<Result>></$list>...</$set>
  • The second number (e.g. 1/3) works fine, but does not count the shadow tiddlers that are part of the core, and I don’t know why…
<$count filter="[tag<currentTiddler>]" />

Shadow tiddlers aren’t included in filter results by default; you’ll want to use

<$count filter="[all[shadows+tiddlers]tag<currentTiddler>]" />

to explicitly include them.

2 Likes

Thank you! Now the second number is always the right one

Here is another variant, which might be slightly faster (not verified):

<$count filter="[<currentTiddler>tagging[]]" />

Fred

One problem with this code is that {{!!title}} in TiddlerTagged definition refers to the tag title, not the tagged tiddler title. <<storyTiddler>> variable should work in this case, but maybe not outside of the StoryRiver.

Here’s the result:

\define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
\whitespace trim
<$vars
	foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">>
	backgroundColor=<<__colour__>>
>
<$element-tag$
	$element-attributes$
	class="tc-tag-label tc-btn-invisible"
	style=<<tag-pill-styles>>
>
	<<__actions__>>
	<$transclude tiddler=<<__icon__>>/>
	<$view tiddler=<<__tag__>> field="title" format="text" />
&nbsp;
<$let
  thisPosition={{{ [<currentTiddler>get[list]enlist-input[]] :else[<currentTiddler>tagging[]] +[allbefore<storyTiddler>count[]add[1]] }}}
  thisCount={{{ [<currentTiddler>tagging[]count[]] }}}
>
<<thisPosition>>/<<thisCount>>
</$let>
</$element-tag$>
\end

The significant part being:

<$let
  thisPosition={{{ [<currentTiddler>get[list]enlist-input[]] :else[<currentTiddler>tagging[]] +[allbefore<storyTiddler>count[]add[1]] }}}
  thisCount={{{ [<currentTiddler>tagging[]count[]] }}}
>
<<thisPosition>>/<<thisCount>>
</$let>

I modified some parts of your original code which certainly worked as-is, just because I tend to avoid the {!!fieldname} construct in macros…

Fred

1 Like

I see, thank you!

It works flawlessly, thank you so much!

Interesting, may I ask why you avoid it? (btw I’ll try to do the same)

Well, [<currentTiddler>get[fieldname]] does the same as [{!!fieldname}] but I prefer the former because both part can be variable, the tiddler name and also the field name. Not sure you should take my word as a rule though :man_shrugging:

Anyway, I’m glad I could help :slightly_smiling_face:

Fred

1 Like

Inspired by this thread I realised we don’t indicate in the tag pill or other list macros if the “current tiddler is listed”, with tags it is typically in the list by definition.

  • A modification/alternative list item template is all that is needed
  • It could be used in other lists

In the tiddler $:/core/ui/TagTemplate it calls the list-tagged-draggable macro and I changed the itemTemplate to another $:/PSaT/listItems/underline-story

<$macrocall $name="list-tagged-draggable" tag=<<currentTiddler>> itemTemplate="$:/PSaT/listItems/underline-story"/>

$:/PSaT/listItems/underline-story contains;

<div class="tc-menu-list-item"><$list filter="[<currentTiddler>match<storyTiddler>]" emptyMessage="<$link/>">__<$link />__</$list></div>

The result is if the current tiddler, using the storyTiddler variable is listed in the tag pill dropdown it will be underlined.

For example this tag pill is on the tiddler “Browse Filter widget”

  • Note the tag pill dropdown has a lot of features on it, due to my reimagine tags solution
3 Likes

There are exceptions: if a tag tiddler exists and has a list field (because tagged tiddlers have been reordered for example), newly created tiddlers won’t appear in the list until the list is modified again.

This occurred to me while working on OP, the solution is not perfect because of this corner case, but I couldn’t find a better solution…

Fred

I raised this “list field not updated”, recently here or in github. I could not find the reference just now.

However note in $:/core/ui/TagTemplate that is calls list-tagged-draggable;

<$macrocall $name="list-tagged-draggable" tag=<<currentTiddler>> itemTemplate="$:/PSaT/listItems/underline-story"/>

Which says;

Note that the ordering is accomplished by assigning a new list to the list field of the tag tiddler. Any list-before or list-after fields on any of the other tiddlers carrying the tag are also removed to ensure the list field is respected.

Also a quick test shows if already re-ordered (list field created) a newly tagged item appears at the bottom.

  • I think this is only true for the list draggable macros.

Yes, I guess I’ll have to study the list-tagged-draggable macro code to understand how the ordering is done in tag pills dropdown. It’s not only “Dominant Append”, there must be something else…

Fred