Tag-pill as a button

378 views
Skip to first unread message

Thomas Stone

unread,
Jan 8, 2021, 12:54:44 PM1/8/21
to TiddlyWiki
I see the documentation on the tag-pill macro is missing the examples. I was wondering how the "actions" parameter would be filled out.

Sebastián Ortega

unread,
Jul 6, 2021, 12:04:25 PM7/6/21
to TiddlyWiki
I'm resurrecting this thread because it happens to me to be in the same situation: I want to make some tag-pill to execute some action.

The action I want to run is navigation to a tiddler whose name is stored in a field. I know how to make it work with a button:

\define actions() <$action-navigate $to={{!!source_type}}/>

<$button actions=<<actions>>>Click me!</$button>


But when I try to do the same with a tag-pill it doesn't do anything:

<$macrocall $name="tag-pill" tag={{!!source_type}} actions=<<actions>>/>

I've attached the JSON version of this to save you copy pasting time if you want to try and see yourselves.
I suspect actions works differently for tag-pill but there are no working examples in tiddlywiki.com.

Any clue?
Sample book tiddler.json

Mat

unread,
Jul 6, 2021, 5:14:57 PM7/6/21
to TiddlyWiki
Just a guess but maybe this part

{{!!source_type}}

has lost its context (i.e the currentTiddler) and seeks for souce_type in the tag(-tiddler)? I.e what is currentTiddler in the action? One way to test is to add a source_type field in the tag-tiddler to see if it does navigate to there.
Again, just a guess.

<:-)

Sebastián Ortega

unread,
Jul 6, 2021, 5:19:36 PM7/6/21
to TiddlyWiki
It works fine for the button but not for the tag-pill.

Anyway, hardcoding a concrete name is also not working:

\define actions() <$action-navigate $to="Target"/>

<$macrocall $name="tag-pill" tag={{!!source_type}} actions=<<actions>>/>

Eric Shulman

unread,
Jul 6, 2021, 6:06:11 PM7/6/21
to TiddlyWiki
On Tuesday, July 6, 2021 at 9:04:25 AM UTC-7 mehequeda...@gmail.com wrote:
The action I want to run is navigation to a tiddler whose name is stored in a field. I know how to make it work with a button:
\define actions() <$action-navigate $to={{!!source_type}}/>
<$button actions=<<actions>>>Click me!</$button>

But when I try to do the same with a tag-pill it doesn't do anything:
<$macrocall $name="tag-pill" tag={{!!source_type}} actions=<<actions>>/>

In order for the tag-pill macro to invoke an $action-* widget, you need to specify element-tag="$button".

Try this:
\define actions() <$action-navigate $to=<<__tag__>>/>
<$macrocall $name="tag-pill" element-tag="$button" tag={{!!source_type}} actions=<<actions>>/>

enjoy,
-e

TW Tones

unread,
Jul 6, 2021, 7:35:25 PM7/6/21
to TiddlyWiki
Eric,

This is an interesting reuse of the tag-pill macro. Thanks for sharing. The tag macro is not too well documented but seems to have a lot of possibilities/parameters, although not documented.

For example I wanted to have a label on a tag-pill, rather then the tag name yet have the same tag drop down. Can you suggest a method? Ideally without modifying the macro?

If it needs a modification to allow an alternate label I would go ahead request an update to the macro to support this.

This would complement a suit of macros I have to enhance the tag drop down. And make use of the actions mentioned in the OT.

As we know the use of the tag pill drop-down is a common tiddlywiki element, its extensible and people know how to use it, it is a useful element to extend somewhat. A concept I wanted to work on is what I named "action tags", ie tags that have the ability to click on and select an action relating to a tag. Eg the task tag could allow you to toggle the done tag.

Thanks
Tones

Eric Shulman

unread,
Jul 6, 2021, 9:35:24 PM7/6/21
to TiddlyWiki
On Tuesday, July 6, 2021 at 4:35:25 PM UTC-7 TW Tones wrote:
I wanted to have a label on a tag-pill, rather then the tag name yet have the same tag drop down. Can you suggest a method? Ideally without modifying the macro?

Changing the tag-pill output will, of necessity, require modifying the macro.  However, you can define a local variant of the tag-pill-inner() macro code, rather than changing the core definition.

My TiddlyTools TagCloud is an example of a modified tag macro:
In this code, I add a "tag count" to the tag-pill display.  I did this by first copying the tag-pill-inner() definition from $:/core/macros/tag, and then adding display of the $(count)$ variable, the value of which was set by my code, before invoking the <<tag>> macro entrypoint.  Here's my customized version of tag-pill-inner()

\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" /> ($(count)$)
</$element-tag$>
</$vars>
\end

For your example -- using an alternative label instead of the tag name ---, you could do something similar, by replacing the part of tag-pill-inner() code that displays the icon and tag name, like this:
\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$<$text text="""$(label)$"""/>
</$element-tag$>
</$vars>
\end

Then, let's suppose you want to show the tag's caption text as the label...you would invoke the <<tag>> macro like this:
<$vars label={{!!caption}}><<tag>></$vars>

or, if you want to use some specific literal text:
<$vars label="argle bargle"><<tag>></$vars>

Note that the <<tag>> macro relies upon the value of <<currentTiddler>> to determine which tag is being rendered.

enjoy,
-e

TW Tones

unread,
Jul 6, 2021, 11:35:20 PM7/6/21
to TiddlyWiki
Thanks so much Eric,

Just what I wanted to know. I assume as long as my tag pill inner is lower on the list of items tagged $:./tags/Macro then it will override the core?

Such core macro overrides would be a useful thing, perhaps however we need a mechanism to indicate when this is occurring?

Here I use the variable tag-label and default to the tag name
<$text text={{{ [[$(tag-label)$]!is[blank]] ~[[$tag$]] }}}/>

calling tags as follows
<$vars tag-label="argle bargle"><<tag>></$vars>

Thanks again, this is a tip I expect to use elsewhere
Tones

Sebastián Ortega

unread,
Jul 7, 2021, 4:49:10 AM7/7/21
to TiddlyWiki
Thanks Eric for the non-obvious solution.

For completeness I tried to use element-tag="$link" hoping that I would get the tag-pill graphic but the functionality of a link. However it looked like a link.

Also thanks for the trick about partial overriding core macros. I have some customization to have a dropdown to choose tags for some other field that only authors have in my wiki and I copy-paste-modified the whole thing.

unread,
Jul 7, 2021, 7:05:17 AM7/7/21
to TiddlyWiki
Hello,

I used TagCloud from Eric and added a third option to see only my tiddlers:

\define tagcloud_showbytiddler()
<$list filter="[!is[system]tags[]sort[]]">
   <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}>
      <<tag>>
   </$vars>
</$list>
\end

This shows me also "$:/tags/Stylesheet"," $:/tags/SideBar", " $:/tags/PageControls" etc...
How can this be excluded from the list?

Thanks
Stefan

Mat

unread,
Jul 7, 2021, 7:42:27 AM7/7/21
to TiddlyWiki
Tones wrote:
For example I wanted to have a label on a tag-pill, rather then the tag name yet have the same tag drop down. Can you suggest a method? Ideally without modifying the macro?

You could experiment with CSS which, in one sense, is perfect for labels and to "not modify the macro". With the coming 5.1.2 we will have css-targetable tags. You can then label the tab via a css pseudo element, something like so (this is just rough to illustrate the idea)

span[data-tag-title="xxxxx"]:after {
content:"MYLABEL";
position:absolute;
left:0;
background:red;
}

<:-)

TW Tones

unread,
Jul 7, 2021, 8:27:12 AM7/7/21
to TiddlyWiki
Mat,

Yes, I am looking forward to such opportunities but I wanted to use the <<tag tagname>> as normal and sometimes change the label. 

The solution I have from this thread is good though.

Would your suggestion still leave the tagname also in the label?.

Regards
Tones

Mat

unread,
Jul 7, 2021, 8:57:44 AM7/7/21
to TiddlyWiki
Tones wrote:
Would your suggestion still leave the tagname also in the label?.

If you don't style it to not show, then yes.

<:-)

Eric Shulman

unread,
Jul 7, 2021, 9:11:32 AM7/7/21
to TiddlyWiki
On Wednesday, July 7, 2021 at 4:05:17 AM UTC-7 S² wrote:
I used TagCloud from Eric and added a third option to see only my tiddlers:

\define tagcloud_showbytiddler()
<$list filter="[!is[system]tags[]sort[]]">
   <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}>
      <<tag>>
   </$vars>
</$list>
\end

This shows me also "$:/tags/Stylesheet"," $:/tags/SideBar", " $:/tags/PageControls" etc...

Instead of
<$list filter="[!is[system]tags[]sort[]]">
you should write:
<$list filter="[tags[]!is[system]sort[]]">

The difference is that the first filter means "for all tiddlers that are not system tiddlers, get all tags"
while the second filter means "get all tags that are not system tiddlers"

-e

unread,
Jul 7, 2021, 9:13:58 AM7/7/21
to TiddlyWiki
Thanks Eric - that's working!
Reply all
Reply to author
Forward
0 new messages