How to display as tag pill iff there are tiddlers tagging, mere link if not

Apologies for not hammering out the logic myself, but maybe this is a common-enough interest to be usefully documented here:

I’d like to list links under a filter condition, but have each link display conditionally in tag-pill form ({{|| $:/core/ui/TagTemplate }}) if and only if it has “children” tagging it, and in regular tiddlylink form (<$link /> ) otherwise.

I’m guessing this is child’s play for some of you… Would you be willing to share?

<$list filter="condition"><<tag "$:/core/ui/TagTemplate">></$list>

is one way, just place your own condition in the filter.

I tried what @TW_Tones suggested and here’s what it did.

But this might be what was intended

<$list filter="[tag[Journal]]">{{||$:/core/ui/TagTemplate}}</$list>

To stop repeats start your filter condition with [all[current] or end with limit[1] depending on the case.

Perhaps you could state what you want a little more clearly. I am now at my desk and want to give you full answer but struggling to answer fully as your question is brief and a little short of information. Perhaps tell us under what condition?

I also have no test data and can’t really create it from your description:

What follows is an attempt to second guess your needs.

<$set name=mytiddler value=<<currentTiddler>> >
<$list filter="list condition">
   <!-- uses "list condition" and sets currentTiddler variable, to generate a list of tiddlers-->
   <$list filter="[all[current]tag<mytiddler>]" emptyMessage="<$link/>" >
        {{|| $:/core/ui/TagTemplate }}
        <!-- if current tiddler in list tagged by <mytiddler> if not use emptyMessage -->
   </$list>
</$list>
</$set>

above untested

Gee, I thought the situation was fairly intuitive. Thanks for your replies so far, but I should clarify:

I want to list all tiddlers tagged ‘definitions’ (say), and the list should look just like the familiar list-links EXCEPT that I see a tag pill (in its proper within the alpha-order list) for exactly those items which itself have tag-children.

For example, I have a tiddler for ‘logic’ (tagged definitions) and there are also other subordinate tiddlers tagging ‘logic’ as well. But the definition-tiddler for ‘premise’ is “bottom-level” – it has a definition tag, but nothing tags to it.

I don’t want tag-pills to display for ‘premise’ and other low-level tiddlers in the list, because it’s irksome to see a tag and click on it, and find that there’s nothing there beyond the tiddler itself.

Having tag pills exactly where they “contain” something is a visually clear way of inviting visitors to recognize that there’s “depth” to some of the items, and not to others.

(I think I recall someone somewhere had a nifty way that a tag pill could show the number of tiddlers tagged, right there at the right edge of the tag pill. That would be even better, but my hope is that if the number of items so tagged is zero, then we should see an ordinary link.)

Does that clarify?

Thanks!
-Springer

G’day,

Create a new tiddler in TiddlyWiki.com and give the code below a spin to see if it either of the two lists match what you’re looking for appearance-wise.

Cheers !

<$list filter="[tag[Filter Operators]]">
<$vars taggedCount={{{ [<currentTiddler>tagging[]count[]] }}}>
{{||$:/core/ui/TagTemplate}} <<taggedCount>><br>
</$vars>
</$list>

<$list variable="thisTiddler" filter="[tag[Filter Operators]]">
<$vars taggedCount={{{ [<thisTiddler>tagging[]count[]] }}}>
<$list filter="[<taggedCount>!match[0]then<thisTiddler>]">
{{||$:/core/ui/TagTemplate}} <<taggedCount>>
</$list>
<$list filter="[<taggedCount>match[0]then<thisTiddler>]">
<$link/>
</$list>
 <br>
</$vars>
</$list>
1 Like

Charlie, the second of these (= the code lines quoted above) is just what I was seeking, Thanks!!

(A small fun future project would be embedding the number-count somehow within the tag pill boundary, but that’s gravy.)

I hope others find the same little code-snippet helpful as well.

-Springer

add the following to your tiddler:

\define tag-pill-inner() ---------- copied from $:/core/macros/tag - added $(taggedCount)$ display in pill
\define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
<$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" /> ($(taggedCount)$)
</$element-tag$>
</$vars>
\end

The above code is a modified copy of a macro defined in $:/core/macros/tag, and adds the display of $(taggedCount)$ inside the tag pill. Of course, you can then remove the display of <<taggedCount>> from your code.

enjoy,
-e

Beautiful! Thanks so much Eric!

-Springer

Sharing out an example of this solution within a more complex glossary project, hosted on the web here:

Glossary of terms at ethics site

3 Likes