Add/remove tags to/from listed tidders

how to add (or remove) a TAG to all the tiddlers which are part of the LIST field of a particular tiddler ?

Maybe it can be done with a action-listops widget https://tiddlywiki.com/#ActionListopsWidget
but i’m not able to set it up right.
thanks for help!!

As far as I know, anything that accepts actions also accepts wikitext that creates multiple actions. So you could use the <$list> widget to create one action for each item.

I believe it would look something like this:

<$list filter="[enlist{targetTiddler!!list}]">
<$action-listops $tags="[[tag to add]] -[[tag to remove]]"/>
</$list>

(See enlist Operator. Depending on your needs, you may also find enlist-input Operator useful, especially when you can’t hardcode the tiddler whose list field you need.)

2 Likes

Super - THANKS a lot !!

just had to add a space behind enlist and it worked perfect

<$list filter="[enlist {targetTiddler!!list}]">
<$action-listops $tags="[[tag to add]] -[[tag to remove]]"/>
</$list>

EDIT: NO it does not work like that

1 Like

Happy to help!

Also, whoa, that’s interesting, and from what I understand, it shouldn’t take a space there!

now i see - No it does not work…
is does add the Tag to every Tiddler - so the enlist filter does not work here :frowning:
What could i try next?

First, for debugging purposes, copy the filter to somewhere you can see the results such as the advanced search or simply make a list that displays the results rather than actioning them.

<$list filter="[enlist{targetTiddler!!list}]" join="<br>"/>

Assuming “targetTiddler” is the tiddler that has the list field, what does this display? (And what all is in the list field?)

ok

<$list filter="[enlist{targetTiddler!!list}]">
<$action-listops $tags="[[tag to add]] -[[tag to remove]]"/>
</$list>

just WORKS !!!

i did not understand that “!!list” after the tiddler title is part of it all :wink:

thanks again…

NOW is there a way to build a universal Form for that so that a funktion works with every tag and list ?
is there a way to but variables in for
“targetTiddler”
and
“tag to add”
???

So you’ve probably figured it out now, but in general, {{tiddlerTitle!!fieldName}} retrieves(transcludes) the field called “fieldName” of the tiddler called “tiddlerTitle”. (And in filters, we use single curly braces to replace the “[” and “]”, as in, {tiddlerTitle!!fieldName}.) The “!!list” means “get the ‘list’ field”.

There are several ways. I think the simplest is to use the enlist-input operator (mentioned in my initial answer)

In order to take this approach, note that, just like we can use single curly braces “{}” to transclude inside filter expressions, we can use single “<>” to use variables inside filter expressions (where the “<” and “>” replace “[” and “]”). So if you have variables <<targetTiddler>> and <<tagToAdd>>, you can use them like this:

<$list filter="[<targetTiddler>get[list]enlist-input[]]">
<$action-listops $tags="[<tagToAdd>]"/>
</$list>

That said, if you are building a form, your text fields (etc.) are bound to tiddlers, not variables. So, most likely, you will not have <<targetTiddler>> but instead you might have made a tiddler named something like $:/temp/TiddlerNameInputValue which stores the value you have typed into an edit-text widget. For example, you might have:

<strong>Target Tiddler:</strong><br>
<$edit-text tiddler="$:/temp/TiddlerNameInputValue"/>`

Then the tiddler “$:/temp/TiddlerNameInputValue” will contain whatever you type into that field. So if you typed “My Special Tiddler” into that field, then $:/temp/TiddlerNameInputValue would contain “My Special Tiddler”.

You can do can do the same thing to make a tiddler to store the tag name. I will assume for the example that the tag name will be stored in a tiddler called “$:/temp/TagNameInputValue” (bound to an input field just like the example above).

Then for your actions, you could have:

<$list filter="[{$:/temp/TiddlerNameInputValue}get[list]enlist-input[]]">
<$action-listops $tags="[{$:/temp/TagNameInputValue}]"/>
</$list>

Edit: I had incorrectly written “enlist-inputs” when the filter operator is actually “enlist-input”. Thanks to @tw-FRed for the correction.

Please beware that the operator is enlist-input without the “s”

https://tiddlywiki.com/#enlist-input%20Operator

Fred

2 Likes

I don’t have a lot of time now, but there is a special case when it comes to lists, it happens to be tags.

Have a look at the WidgetMessages tm-add-tag and tm-remove-tag

These can be used on the button widget message or in the action send message widget.

Thanks for noticing my mistake! I’ll go ahead and edit my response just in case anyone happens to read it and try it without noticing your correction.

One more way (which is probably better than my initial answer) could be with the list operator. It turns out there’s a filter operator designed specifically for getting a tiddler list from a field (by default, the list field) instead of directly in a parameter.

<$list filter="[list[targetTiddler]]">(action widget)</$list>

And this makes even enlist-input unnecessary in my suggestion for how to build a form.

We could replace the above quoted code with:

<$list filter="[list<targetTiddler>]">

Similarly:

We could change this example to:

<$list filter="[list{$:/temp/TiddlerNameInputValue}]">

This is shorter and neater than using enlist-input, but nothing I previously wrote is too unwieldy, so use whatever is easiest for you!

1 Like

Thanks.

i seam to miss few things… if i try this all does not work for me

e.g.
what do I have to put into
$:/temp/TiddlerNameInputValue

??

??

Absolutely nothing! You don’t even have to create it. (Well, not manually.)

In your form, if you add <$edit-text tiddler="$:/temp/TiddlerNameInputValue"/>, it makes a text input field that stores whatever you type in it into the tiddler ‘$:/temp/TiddlerNameInputValue’, and when you type into that text field, it will create that tiddler if it doesn’t already exist.

(Note that the use of that tiddler would specifically be for building a form.)

Not totally sure what else you could be missing, so here’s a complete (minimal) code example that I found to work:

<strong>Tiddler With List:</strong><br>
<$edit-text tiddler="$:/temp/TiddlerNameInputValue" tag="input"/>

<strong>Tag to add:</strong><br>
<$edit-text tiddler="$:/temp/TagNameInputValue" tag="input"/>


<$button actions="""<$list filter="[list{$:/temp/TiddlerNameInputValue}]">
<$action-listops $tags="[{$:/temp/TagNameInputValue}]"/>
</$list>""">Add tag</$button>
1 Like

The filter quoted above means this:
Enlist the values in the list filed of the tiddler whose name in in this tiddler: $:/temp/TiddlerNameInputValue.
Or:
This tiddler: $:/temp/TiddlerNameInputValue contains the name of a second tiddler, and this second tiddler has a field named list and the filter reads its content as separate values.

This is called “indirection”, because in order to get the target tiddler name, you read the content of another tiddler first.

This technique is used by Tiddlywiki core and many plugins when reading configuration values stored in $:/config/... tiddlers.

Hope this helps reading @bluepenguindeveloper 's code (if needed).

Fred

2 Likes

Thanks - your code works perfect - all i was looking for… thanks for teaching me