In a field, append to an existing list - with correct brackets

In a tiddler I have myfield: foo [[bar bar]]

Via my myprocedure(appendthis) I want to set a tiddler field so its value concatenates its old value with the argument, to get the field value foo [[bar bar]] [[just appended]] (or possibly [[foo]] [[bar bar]] [[just appended]]). Order doesn’t matter.

But it is surprisingly difficult to get the brackets right. I get everything from no brackets to quadruples to… well, you get it. I’ve tried format:titlelist[] but nope.

What to do?

\procedure myprocedure(appendthis)
<$button>go
<$action-setfield
	$tiddler=<<currentTiddler>>
	myfield= ...
/>
</$button>
\end
<<myprocedure "just appended">>

Thank you!

Hi Mat

Try this (barely tested):

\procedure myprocedure(appendthis)
<$button>go
<$action-setfield
	$tiddler=<<currentTiddler>>
	myfield={{{ [<appendthis>format:titlelist[]] [{!!myfield}] +[join[ ]] }}}
/>
</$button>
\end
<<myprocedure "just appended">>


;myfield
:<$codeblock code={{!!myfield}}/>

Hope this helps,

Fred

Try this:

<$action-listops $tags=<<currentTiddler>> />

Oh, yeah! Thank you so much!

(reflection: That is certainly too… I don’t know the appropriate word… maybe “special” or “intricate”… I’m a pretty darn experiened TW user and I get trapped in bits like these too often, so I am pretty sure it affects others too… Is it a docs matter? Are we missing operators? Is there a more fundamental problem on the side of TW or myself?.. hmm…)

Hm, I didn’t try it yet, but how can that possibly concatenate anything?

See https://tiddlywiki.com/#ActionListopsWidget

In your example, code would be:
<$action-listops $field="myfield" $subfilter="[<appendthis>]" />

3 Likes

<$action-listops $field="myfield" $subfilter="[<appendthis>]" />

I was just about to post this after some experimentation!

Thank you @tw-FRed and @saqimtiaz

1 Like

Both versions (action-listops and action-setfield) have the same limit: procedure parameter is considered as a single value to be appended to the existing list field.

If the parameter actually contains a list, not a single value, and the purpose is to merge this list with current field content, then it doesn’t work as is.

This. Code that edits lists can be tricky if you want to support spaces in the list items. A more complete documentation reading list, to help you understand what’s available for this kind of thing:

  • action-listops widget
  • enlist filter operator
  • set widget
1 Like
<$let mylist="[[Tiddler A]] [[Tiddler B]] C">
<$button>go<$action-listops $field="myfield" $subfilter=<<mylist>> /></$button>
</$let>
3 Likes