How to filter tags[] result using tag page

Let’s say I have several tiddlers tagged “Person”. Each Person can have several Tasks, each one a tiddler with several tags, one of them “Task” and one of them the name of the person. Now I want to have a list of all Tasks and list the person name tag in front of each task description. The following code will list all tags for each task.

<$list filter="[tag[Task]]">
  <div class="tc-tags-wrapper">
   <!-- How to filter the tag list here? -->
    <$list filter="[all[current]tags[]]"
        template="$:/core/ui/TagTemplate"
        storyview="pop" />     
  </div>
  <<currentTiddler>>
</$list>

In plain English my filter criterion for tags[] would read: “if a Tiddler with the tag title exists AND that tiddler is tagged ‘Person’”

Probably what comes back from tags[] is not a list of tiddlers but a list of strings or tag objects and I need to turn then back to tiddlers to filter them further. Is that mental model correct?

Perhaps

<$list filter="[tag[Task]]">
  <div class="tc-tags-wrapper">
   <!-- How to filter the tag list here? -->
    <$list filter="[all[current]tags[]tag[Person]]"
        template="$:/core/ui/TagTemplate"
        storyview="pop" />     
  </div>
  <<currentTiddler>>
</$list>

I think this post is a pure question and not a wiki. I did remove the wiki flag. …

Once you got a solution that does what you want, you can create a post in the Tips & Tricks category as a wiki.

No, that does not work. But after carefully reading the filter operator documentation, I know why:

Most steps process the selection of titles that are supplied as their input, but a few construct an entirely new selection instead.

My initial hunch that tags[] does not return a selection of titles (where your suggestion could work) seems to be correct, as the output description of the tags operator does not mention a selection of titles:

May be the contains operator does the trick.

    <$list filter="[all[current]tags[]contains:tags[Person]]"

Not tested

I have found two solutions to my problem, one using tags[] and one using different lists:

<$list filter="[tag[Task]]">
  <div class="tc-tags-wrapper">
    <$list filter="[all[current]tags[]]" variable=tagName>
        <!-- TODO can this 3rd list level somehow be folded into the filter above? -->
        <$list filter="[<tagName>tag[Person]]"
            template="$:/core/ui/TagTemplate"
            storyview="pop"
        />     
    </$list>
  </div>
  <<currentTiddler>>
</$list>

The third nested list converts the tag name back to a tiddler. I wonder if that nested list structure could be optimized while still using tags[]?

Another option is a different list nesting and rendering the person tiddler with the tag template:

<$list filter="[tag[Person]]" variable=personT>
  <div class="tc-tags-wrapper">
    <$list filter="[tag<personT>tag[Task]]">
       <!-- TODO find out how to use $:/core/ui/TagTemplate directly -->
       <span class="tc-tag-label" 
             style="background-color:; fill:#333333; color:#333333;">
                <$link to=<<personT>>/>
       </span>
    </$list>
  </div>
  <<currentTiddler>>
</$list>

I could not figure out how to transclude $:/core/ui/TagTemplate with ´personT´ as the current tiddler, so I took some styles from the template to at least have the pill appearance of the tags.

With the transclude widget

<$tiddler tiddler=<<personT>> >
<$transclude tiddler="$:/core/ui/TagTemplate"/>
</$tiddler>

With WikiText

<$tiddler tiddler=<<personT>> >
{{||$:/core/ui/TagTemplate}}
</$tiddler>

In your case you could even use filtered transclusion :

{{{ [<personT>] ||$:/core/ui/TagTemplate}}}

See https://tiddlywiki.com/#Transclusion%20in%20WikiText