Add/Remove Tags from Tiddler

603 views
Skip to first unread message

Steven Schneider

unread,
Jul 27, 2018, 10:04:53 AM7/27/18
to TiddlyWiki
Hello Old Friends:

I'm trying to write a macro that would add & remove tags from a tiddler with a single button. I've got it working with two buttons, but am quite sure I'm missing something very simple. Any suggestions would be much appreciated. Thanks, //steve.

\define makeOld()
<$fieldmangler>
Add <<tag OldTopics>> 
<$button message="tm-add-tag" param="OldTopics">{{$:/core/images/new-button}}</$button>
<br>
Remove <<tag Topics>>
<$button message="tm-remove-tag" param="Topics">{{$:/core/images/delete-button}}</$button>
</$fieldmangler>
\end

<<makeOld>>


Mark S.

unread,
Jul 27, 2018, 10:36:43 AM7/27/18
to TiddlyWiki
So, you want to do the two things at the same time? This seems to work:

\define myactions()
<$fieldmangler>
<$action-sendmessage $message="tm-add-tag" $param="OldTopics"/>
<$action-sendmessage $message="tm-remove-tag" $param="Topics"></$button>
</$fieldmangler>
\end
\define makeOld()
Add <<tag OldTopics>> Remove <<tag Topics>>
<$button actions=<<myactions>>>{{$:/
core/images/erase}}
</$button>
\end

<<makeOld>>

I changed the two buttons to an erase button since there is now one button to do two things. But of course you can decorate it however you want. The actions were moved to a macro and activated through the "actions" attribute of the button, which is supposed to be the new way of doing things.

HTH

-- Mark

Steven Schneider

unread,
Jul 31, 2018, 11:21:22 AM7/31/18
to TiddlyWiki
Thanks, Mark. Worked perfectly!

Uwe

unread,
Aug 1, 2018, 12:13:19 PM8/1/18
to TiddlyWiki
Hm, I'm wondering, why this code doesn't work at tiddlywiki.com.
Greetings,

Uwe

Mark S.

unread,
Aug 1, 2018, 12:58:08 PM8/1/18
to TiddlyWiki
Works fine when I test it. Note that it doesn't toggle between the two states -- that wasn't the original request.

-- Mark

Thomas Elmiger

unread,
Aug 5, 2018, 9:10:19 AM8/5/18
to tiddl...@googlegroups.com
Hi folks,

I use the fabulous listops action for this (a bit complicated but reusable):

\define BtnTagListops(btntext,add-remove,tooltip)
<$button tooltip="""$tooltip$""">
<$wikify name="timestampState" text="{{$:/config/TimestampDisable}}">
<$action-setfield $tiddler="$:/config/TimestampDisable" $value="yes"/>
<$action-listops $tags="$add-remove$" />
$btntext$
<$action-setfield $tiddler="$:/config/TimestampDisable" $value=<<timestampState>>/>
</
$wikify>
</$button>
\end



This does change tags WITHOUT updating timestamps (it stores and restores the previous setting for updating timestamps). I call it from other macros like this one:


\define todoBtnDoNow()
<$wikify name="tt" text="switch tags">
   
<$macrocall $name="BtnTagListops" btntext="Do this now" add-remove="ToDoNow -ToDo" tooltip=<<tt>>/>
</
$wikify>
\end

<<todoBtnDoNow>> adds the tag ToDoNow and removes the tag with the minus (-) ToDo. You could add and remove as many tags as you like.


These are somewhat simplified macros, I hope they still work and it is clear how they work.

Cheers,
Thomas
(Back from offline vacation.)

Mohammad

unread,
Jan 10, 2019, 5:12:41 AM1/10/19
to TiddlyWiki
Great solution Thomas. There is small typo I corrected below

\define BtnTagListops(btntext,add-

remove,tooltip)
<$button tooltip="""$tooltip$""">
<$wikify name="timestampState" text="{{$:/config/TimestampDisable}}">
<$action-setfield $tiddler="$:/config/TimestampDisable" $value="yes"/>
<$action-listops $tags="$add-remove$" />
$btntext$
<$action-setfield $tiddler="$:/config/TimestampDisable" $value=<<timestampState>>/>
</
$wikify>
</$button>
\end


Calling macro

\define todoBtnDoNow()
<$wikify name="tt" text="switch tags">
   
<$macrocall $name="BtnTagListops" btntext="Do this now" add-remove="ToDoNow -ToDo" tooltip=<<tt>>/>
</
$wikify>
\end


In the second script (calling macro, the correct $name="BtnTagListops" instead of teBtnTagListops.


Cheers
Mohammad



On Sunday, August 5, 2018 at 5:40:19 PM UTC+4:30, Thomas Elmiger wrote:
Hi folks,

I use the fabulous listops action for this (a bit complicated but reusable):

\define BtnTagListops(btntext,add-remove,tooltip)
<$button tooltip="""$tooltip$""">
<$wikify name="timestampState" text="{{$:/config/TimestampDisable}}">
<$action-setfield $tiddler="$:/config/TimestampDisable" $value="yes"/>
<$action-listops $tags="$add-remove$" />
$btntext$
<$action-setfield $tiddler="$:/config/TimestampDisable" $value=<<timestampState>>/>
</$wikify>
</$button>
\end

This does change tags WITHOUT updating timestamps (it stores and restores the previous setting for updating timestamps). I call it from other macros like this one:

\define todoBtnDoNow()
<$wikify name="tt" text="switch tags">

   <$macrocall $name="teBtnTagListops" btntext="Do this now" add-remove="ToDoNow -ToDo" tooltip=<<tt>>/>
</$wikify>
\end

Thomas Elmiger

unread,
Jan 10, 2019, 6:07:14 AM1/10/19
to TiddlyWiki
Thank you, Mohammad! I corrected the typo also in my previous post, just in case anyone stops reading there.

Cheers,
Thomas

TonyM

unread,
Jan 10, 2019, 7:15:39 AM1/10/19
to TiddlyWiki
A quick note - back on the original post.

The Need to remove one tag when adding another to toggle a state needs to occur everywhere in the wiki the same way or you may end up with both or neither.

This is why I tend to move it to a common field name with one of the possible values only permitted at a time.

Once you become used to has[fieldname] get[fieldname] {{!!fieldname}} has:field[fieldname]] its easier than managing tag toggles and can protect you from the inconsistencies allowing only one value at a time.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages