Using a variable in $action-listops

Greetings,

I’ve been trying to evolve my learning and wanted to take a tool I have to toggle a list of tiddlers between two tags. Clicking an item will toggle it from #q1 to #q2 or vice versa:

#q1
[ ] Item 1
[ ] Item 2

#q2
[ ] Item 3
[ ] Item 4

The code below works great…


!#q1
<$list filter="[tag[#q1]]">
<$button class="tc-btn-invisible">
<input type="checkbox"/>
<$action-listops $tags="#q2 -#q1"/>
</$button>

<$link to={{!!title}}><$view field="title"/></$link>
<br>
</$list>

!#q2
<$list filter="[tag[#q2]]">
<$button class="tc-btn-invisible">
<input type="checkbox"/>
<$action-listops $tags="#q1 -#q2"/>
</$button>

<$link to={{!!title}}><$view field="title"/></$link>
<br>
</$list>

…, however, I want to up my game by only having to define the tags in one place, rather than change them everywhere each time.

After much struggle I am so close but am stumped with how to define the variable in the $action-listops sections:


<$set name="firstTag" value=#q1>
<$set name="secondTag" value=#q2>

Clicking on a checkbox will move that item from <<firstTag>> to <<secondTag>> or vice versa

!<<firstTag>>

<$list filter="[tag<firstTag>]">
<$button class="tc-btn-invisible">
<input type="checkbox"/>
<$action-listops $tags="-<<firstTag>> <<secondTag>>"/>
</$button>

<$link to={{!!title}}><$view field="title"/></$link>
<br>
</$list>

!<<secondTag>>
<$list filter="[tag<secondTag>]">
<$button class="tc-btn-invisible">
<input type="checkbox"/>
<$action-listops $tags="<<firstTag>> -<<secondTag>>"/>
</$button>

<$link to={{!!title}}><$view field="title"/></$link>
<br>
</$list>

</$set>
</$set>

These are the lines giving me trouble. I am trying to remove the #q1 tag and add the #q2 tag in the first section:

<$action-listops $tags="-<<firstTag>> <<secondTag>>"/>

And the reverse in the second section:

<$action-listops $tags="<<firstTag>> -<<secondTag>>"/>

I managed to figure out to use single brackets in the filter, double brackets elsewhere, but in the $action-listops portion I have tried double brackets, single brackets, $$ signs, $()$ signs, crying, cursing and throwing up my hands…, all to no avail. I feel like I am missing something obvious. Any help would be much appreciated.

The $tags parameter is actually a filter to be applied to the tags field content. In your previous code, you used literal text tag values “#q1” and “#q2”, so your filter syntax was just “#q2 -#q1”. Note that this could have been written as “[[#q2]] -[[#q1]]”, where the double-square brackets would also permit the use of literal text tag values that contain embedded spaces (e.g., “[[some tag]] -[[some other tag]]”)

To replace these literal values with variables named firstTag and secondTag, you would use the [<varname>] filter syntax, like this:

<$action-listops $tags="-[<firstTag>] [<secondTag>]"/>
and
<$action-listops $tags="[<firstTag>] -[<secondTag>]"/>

Also, instead of using $set widgets to define the variables like this:

<$set name="firstTag" value=#q1>
<$set name="secondTag" value=#q2>

you can use just one $let widget, like this:

<$let firstTag="#q1" secondTag="#q2">

enjoy,
-e

2 Likes

Eric,

I can’t thank you enough for the help. I really appreciate not only the solution, but the explanation as well. And the freebie, too! I hadn’t explored $let at all yet. Elegant. Looks like I’ll have to upgrade that particular wiki in order to take advantage of it, and will do so shortly.

Have appreciated you all these years. Thanks!

MR

1 Like