Combining Templater (in frontmatter) and Dataview

What I’m trying to do

I want to make a note template with a tag in the frontmatter that is called using this Templater snippet:

<%*
const tags = Object.keys(app.metadataCache.getTags())
let selection = await tp.system.suggester([...tags, "Make New"], [...tags, "Make New"])
if (selection === "Make New") {
    selection = await tp.system.prompt("new tag")
}
tR += selection
%>

this tag then also should be replaced in this Dataview code:

LIST item.children.text FROM #tag
FLATTEN file.lists as item
WHERE contains(item.tags, "#tag")

Things I have tried

I tried to insert the Templater snipped in the tag frontmatter first but there I only get a empty field.
When using the Templater snippet directly in the Dataview code, I get an error (probably becasue it is inserted two times?)

How can I combine the two to work together and with the frontmatter?

Not sure if there are more elegant solutions (also I still don’t understand everything that’s going on in that code)… but it works.

If you have improvements, feel free to let me know :slight_smile:

<%*
const tags = Object.keys(app.metadataCache.getTags())
let selection = await tp.system.suggester([...tags, "Make New"], [...tags, "Make New"])
if (selection === "Make New") {
    selection = await tp.system.prompt("Enter a new tag (without #)")
}
tR = `---
tags: ["${selection}"]
---`
%>

```dataview
LIST item.children.text
FLATTEN file.lists as item
WHERE contains(item.tags, this.file.tags[0])
```

Since you’re using templater, you could instead of this.file.tags[0] use <% selection %>