Adding/Removing Tags Via Checkboxes

Hello,

I am attempting to list all tiddlers with a tag of “BK/Object/Topic” and then want to be able to select one or more, and have all tiddlers that have a link to the selected tiddlers display in a separate tiddler.

I am not sure what I am doing wrong, so would appreciate any assistance!

<$button>
Filter Links
<$action-setfield $filter1="[all[shadows+tiddlers]tag[filter]]" $filter2="backlinks[] +[all[shadows+tiddlers]tag[filter]]" $filter3="field:title<<filter1>>" filter=""/>
</$button>

<$list filter='[all[shadows+tiddlers]tag[filter]]' variable=LinksOne>
  <$link>''{{!!title}}<br>
  ''</$link>
</$list>

<$list filter='[all[shadows+tiddlers]tag[filter]]' variable=LinksTwo>
  <$list filter='[BK/Object/Topic[]tags[]intersect<LinksOne>backlinks[]]'>

    <$link>''{{!!title}}<br>
    ''</$link>

  </$list>
</$list>```

I am not even sure what you are trying to do, I see a number of apparent errors in your code but I do not know what it supposed to do.

Could you spell out what you want with a little more details please?, it would be easier to give you the full solution.

Try this:

First, create a tiddler (e.g., “FindBacklinks”), containing:

<$list filter="[all[shadows+tiddlers]tag[BK/Object/Topic]sort[]]" variable="tid">
   <$checkbox listField="selected" checked=<<tid>>> <$text text=<<tid>>/></$checkbox><br/>
</$list>

Then, create another tiddler (e.g., “ShowBacklinks”), containing:

<$list filter="[enlist{FindBacklinks!!selected}sort[]]" variable="tid">
   <$list filter="[<tid>backlinks[]limit[1]]" variable="has_backlinks">
      <$link to=<<tid>>/> is linked from:
      <blockquote><$list filter="[<tid>backlinks[]]"><$link/><br/></$list></blockquote>
   </$list>
</$list>
1 Like

Apologies, I was in a bit of a rush last night and didn’t have time to fully explain what I was trying to do.

Let’s suppose that I have a tiddler called TiddlerA. In it, it has a link to another tiddler called TiddlerLink1 and then a link to another tiddler called TiddlerLink2. Both TiddlerLink1 and TiddlerLink2 are tagged with “BK/Object/Topic”.

I want to be able to select one or multiple tiddlers that are tagged with “BK/Object/Topic”, and then have any tiddlers that link to the selected tiddlers listed out.

1 Like

Eric,

Thanks so much for this. This is very close to what I am trying to do. However, this loops through each selected tiddler and for each selected tiddler, it displays tiddlers that link to it. What I am wanting is to list tiddlers that link to all the selected tiddlers. If I selected two tiddlers, I want a list of tiddlers that link to both of those!

@EricShulman Do you have any thoughts on the above?

Try this:

!!!Tiddlers linked to <$text text={{{ [enlist{FindBackLinks!!selected}sort[]join[ AND ]] }}}/>

<$list filter="[{FindBackLinks!!selected}!match[]]" variable="none">
   <$list filter="[all[]]" variable="tid">
      <$list filter="[enlist{FindBackLinks!!selected}] -[<tid>links[]] +[count[]match[0]]">
         <$link to=<<tid>>/><br>
      </$list>
   </$list>
</$list>
  • The first $list makes sure that at least one checkbox was selected.
  • The second $list looks through all tiddlers
  • The third $list subtracts all the links in the current tiddler from the selected links. If this results is an empty list, then it means that the tiddler links to ALL of the selected links.

@EricShulman thanks so much for this! This worked perfectly.

Is there any way this could be cloned and then slightly modified to then work for the OR operator instead of AND?

Try replacing this line:

<$list filter="[enlist{FindBackLinks!!selected}] -[<tid>links[]] +[count[]match[0]]">

with:

<$list filter="[enlist{FindBackLinks!!selected}] :filter[<tid>links[]match<currentTiddler>] +[count[!match[0]]">
  • filter:[<tid>links[]match<currentTiddler>] keeps any link in the current tiddler that matches a selected link. Note that within the :filter context, <currentTiddler> refers to each title from the preceding filter run (i.e., a selected title).

@EricShulman Hmm that unfortunately did not work. It grabbed ALL the tiddlers in the entire wiki.

There was a copy/paste error in the code I posted! Somehow the closing ] for the count[] filter operator got dropped.

It should be:

<$list filter="[enlist{FindBackLinks!!selected}] :filter[<tid>links[]match<currentTiddler>] +[count[]!match[0]]">

@EricShulman that worked! Thank you so much.

There is one last thing I am trying to do.

Currently, I have two forms of organization, one of them being links (what you’ve helped me with) and the other being tags. I have a tiddler with a field field called selected-topics that holds the topics (links) I want to filter with and a field called selected-tags that holds the tags I want to filter with.

In a separate tiddler, I want to do something similar to what I’ve asked previously, but this time I want to list tiddlers that are tagged to all the values (tiddlers) listed in the selected-tags field AND link to all the values (tiddlers) in the selected-topics field.

I’ve tried the below and it isn’t working properly. But my thought process was I could take some of what you did and create a filter that first grabs all tiddlers that are tagged to all the selected tags, and then grab all tiddlers that came out of that that link to all the selected topics.

I am confident my code doesnt line up to what I was trying to do :laughing:

<$list filter="[all[]]" variable="tid">
<$list filter="[enlist{SelectFilters!!selected-tags}] -[<tid>tags[]] +[count[]match[0]] +[enlist{SelectFilters!!selected-topics}] -[<tid>links[]] +[count[]match[0]]" >
         <$link to=<<tid>>/><br>
      </$list>
   </$list>