Unsuccessful attempt at creating a list to quickly add a tag to each item

Hi guys

I tried to create a list so I could a tag to a lot of tiddlers quickly. The only problem is that it adds the tag to the tiddler that the fieldmangler is placed in, rather the tiddler that is the list item.

If anyone can fix this, I would be grateful. Even better would be if I could with one click add the tag to ALL the tiddlers that match the filter.

(I have to do quite a number of phrases for the [search:title[]], and there are hundreds if not more than a thousand tiddlers that need to have a tag added, then a tag removed. Went about this the wrong way.)

<$fieldmangler>
<$list filter="[tag[@A]search:title[dictionary]]"><$link/> / <$view field="tags"/> <$button message="tm-add-tag" param="@Reference-Dicts">{{$:/core/images/new-button}}</$button><br></$list>
</$fieldmangler>

Move the $fieldmangler widget inside the $list, like this:

<$list filter="[tag[@A]search:title[dictionary]]">
   <$fieldmangler>
      <$link/> / <$view field="tags"/>
      <$button message="tm-add-tag" param="@Reference-Dicts">
         {{$:/core/images/new-button}}
      </$button><br>
   </$fieldmangler>
</$list>

You might also want to try TiddlyTools/Search/Filters which lets you enter a filter and then perform bulk operations on the resulting list of tiddlers. For your purposes, after entering a filter, you would click on the “tag” icon (first button in the upper right of the interface). This will open a modal dialog that lets you add and remove tags from all the matching tiddlers.

enjoy,
-e

2 Likes

Supporting @EricShulman’s guidance the fieldmangler operated on the current tiddler

title of the tiddler to manipulate (defaults to the current tiddler)

So by placing it inside the $list widget the correct tiddler will be the current tiddler at the time.

Here’s how I’d go about this with a slightly different technique:

<$button>
	{{$:/core/images/new-button}}
	<$list filter="[tag[@A]search:title[dictionary]]">
		<$action-listops $tags="[[@Reference-Dicts]] -[[tag to be removed]]" />
	</$list>
</$button>

I’m not sure whether you still want to display all the relevant tiddler titles if you’re using the single-button approach, but if you do, you could add <$link/> inside the $list widget, or repeat the same list with links only outside the button.

The key difference here is that, unlike your original code and Eric’s, I’m using the $list inside the button, not outside, which lets me make a list of actions (or rather, the same action applied to many different tiddlers) rather than a list of buttons. I also switched out the $fieldmangler for $action-listops, which takes the existing contents of a field (here, tags in particular) and modifies it based on the filter you provide. This lets you add and remove tags in the same step if you so choose.

The minor downside is that when you supply action widgets inside a $button’s content, all the relevant filters get pre-calculated when the tiddler is first loaded, even if they don’t yield any visible content. If you don’t like this lag, you can move the $action-listops and its wrapping $list into a macro/procedure that gets called as part of the $button actions:

\procedure retag()
<$list filter="[tag[@A]search:title[dictionary]]">
	<$action-listops $tags="[[@Reference-Dicts]] -[[tag to be removed]]" />
</$list>
\end

<$button actions=<<retag>>>
	{{$:/core/images/new-button}}
</$button>

Now all those $action-listops won’t get calculated until you actually press the button.

Finally, if you’re doing a lot of batch-processing like this, I highly recommend the Commander plugin, which gives you a ready-made UI for operations like this.

2 Likes

@EricShulman, maybe you can clear up a question I’d forgotten I had: is there any benefit to using the $fieldmangler/widget message combo over a simple action widget in cases like this? I came across $fieldmangler pretty early in my TW usage and didn’t quite grasp how to use it efficiently, and once I discovered action widgets, I never looked back. Am I missing some untapped potential, or is it just a relic of an older version?

I have never needed to use $fieldmangler. It is only used for handling things like tm-add-tag/tm-remove-tag and tm-add-field/tm-remove-field, which are now handled more effectively by $action-listops and $action-setfield/$action-deletefield, respectively.

As far as I’m concerned, $fieldmangler is “a relic of an older version”, and only exists for backward-compatibility with older plugins that may still be using it.

-e

3 Likes