Button to remove value from field, applied via template

In my ongoing journey to build my Gift Ideas notebook, I’m using a template to display on each tiddler tagged as gift, a draggable list of the to-gift field :

<$macrocall 
$name=list-links-draggable
tiddler=<<currentTiddler>> 
field=to-gift 
itemTemplate=.itemTemplateGiftToGift />

That works just fine. What doesn’t work is what I’m typing in the .itemTemplateGiftToGift to include an × that should remove that entry from the to-gift field:

<$button 
class='tc-btn-invisible tc-btn-mini  tc-small-gap-right'
actions="""<$action-listops $tiddler=<<currentTiddler>> $field="to-gift" $subfilter="-[{!!title}]"/>""">
{{$:/core/images/close-button}}
</$button> <$link/>

I’ve also tried bringing the action-listops outside the button as such:

<$button 
class='tc-btn-invisible tc-btn-mini  tc-small-gap-right'>
{{$:/core/images/close-button}}
<$action-listops $tiddler=<<currentTiddler>> $field="to-gift" $subfilter="-[{!!title}]"/>
</$button> <$link/>

The × doesn’t remove the entries as I thought it would/should. Here’s what looks OK, but doesn’t work OK (I haven’t yet added the × to the list on the right):

Just a guess.

<$action-listops $tiddler=<<currentTiddler>> $field="to-gift" $subfilter="-[<currentTiddler>]"/>

That doesn’t seem to work, either from within or from outside the <$button> parameters.

Due to the various references and templating, I’m a little confused on what <<currentTiddler>> means at that point. The chain of itemTemplatelist-links-draggable macro ← viewTemplate ← actual gift tiddler. I guess it’s the final gift tiddler? If so, why wouldn’t using {!!title} be the same?

Exactly my thought (after having been is similar situations many times). You can add a {{!!title}} just next to the little x for a peek at that value. If that in deed is the problem, you can just $let curr=<<currentTiddler>> somewhere outside the whole construct to use it later inside.

1 Like

What a brilliant idea, this is what I did and I found out that both {!!title} and <currentTiddler> pointed to the current gift, not the current person.

I first defined a variable as you suggested in the viewTemplate, than I adjusted the .itemTemplate as follows (adding the extra debugging and most importantly adding a $tiddler parameter pointing to the <<curr>> variable):

<$button 
class='tc-btn-invisible tc-btn-mini  tc-small-gap-right'
actions=""" <$action-listops $tiddler=<<curr>> $field="to-gift" $subfilter="-[<currentTiddler>]"/> """
style="text-align: left">
- `{{!!title}}`: {{!!title}} <br/>
- `<currentTiddler>`: <<currentTiddler>> <br/>
- `curr`: <<curr>> <br/>
{{$:/core/images/close-button}}
</$button>
<$link/>

Produced this ugly but very informative view:

I adjusted the final button with the $tiddler parameter and now it works as required!

Once again thank you for the idea!

:laughing: yeah thats what my tiddlers look all the time when I code in TW. I can barely take cred for that idea though, I’m pretty sure that’s just “how people do it” when bug hunting.

BTW, one should also know of the tiddlerwidget in these situations, allowing for e.g <$tiddler tiddler=<<curr>> > (…which, come to think of it, probably would be exactly the same as doing $let currentTiddler=<<curr>>). I’m not saying this is necessary for your case, it is just a general technique.