How to generate add- and remove-buttons for every existing tag of a tiddlywiki?

85 views
Skip to first unread message

Uwe

unread,
Aug 22, 2018, 3:28:09 PM8/22/18
to TiddlyWiki
This code provides a button which can be used to add or remove one tag "KA01" to a tiddler:


<$fieldmangler>
  <$list filter="[is[current]tag[KA01]]">
    <$button class="button" message="tm-remove-tag" param="KA01">{{check}}<
<tag KA01>></$button>
  </$list>

  <$list filter="[is[current]!tag[KA01]]">
    <$button class="button" message="tm-add-tag" param="KA01"><
<tag KA01>></$button>
  </$list>
</$fieldmangler>

To avoid copy & paste this code a hundred times and change "KA01" manually for all available tags I think, there must be an easier solution with a macro or so.

I'd like to remove or add every individual tag of my tiddlywiki with a special button (each tag has its own button for add or remove). How is it possible to generate them in a loop?






Mat

unread,
Aug 22, 2018, 3:41:46 PM8/22/18
to TiddlyWiki
I'd say you can basically invert your solution, i.e put the listwidget + actionwidget inside the button.

I have not tested the following, I've blatantly written "$action" where it said "$button" previously so this is just to illustrate my point - it has surely faulty syntax. Also I'm not sure a fieldmangler is needed:

<$button class="button">

<$fieldmangler>
<$list filter="[is[current]tag[KA01]]">
<$action message="tm-remove-tag" param="KA01">{{check}}<<tag KA01>></$button>

</$list>
<$list filter="[is[current]!tag[KA01]]">
<$action message="tm-add-tag" param="KA01"><<tag KA01>></$button>
</$list>
</$fieldmangler>
</$button>


<:-)

Thomas Elmiger

unread,
Aug 22, 2018, 4:48:07 PM8/22/18
to TiddlyWiki
Hi Uwe

I'd like to remove or add every individual tag of my tiddlywiki with a special button (each tag has its own button for add or remove). How is it possible to generate them in a loop?

I have something similar (but different) im my listreveal plugin. The lists are generated like this (I simplify the code a bit for better understanding of the important parts – this is NOT tested):

<ul class="lr-tags-add">
<$list filter=<
<add-tags-filter>> variable="tag">
<li>
   <$macrocall $name="teBtnTagAddRemove" btntext=<
<tag>> add=<<tag>> tiddler=<<tiddler>> tooltip="add"/>
</li>
</$list>
</ul>

<ul class="lr-tags-remove">
<$list filter=<
<remove-tags-filter>> variable="tag">
<li>
   <$macrocall $name="teBtnTagAddRemove" btntext=<
<tag>> remove=<<tag>> tiddler=<<tiddler>> tooltip="remove"/>
</li>
</$list>
</ul>

To make this work you would have to surround it with suitable definitions for all variables, e.g.

<$wikify name="tiddler" text=<<currentTiddler>>>
<$set name="add-tags-filter" value="[tags[]sort[]] -[<tiddler>tags[]]>
<$set name="remove-tags-filter" value="[<tiddler>tags[]]">

...

</$set>
</$set>
</$wikify>

and last but not least you would need my universal macro teBtnTagAddRemove from https://tid.li/tw5/hacks.html#%24%3A%2Fplugins%2Ftelmiger%2Flistreveal%2Ftags

Does this make sense?

Good night and good luck!
Thomas
Reply all
Reply to author
Forward
0 new messages