When are you inserting this template? At creation of the note, or after the note has been populated with content?
If at creation you are getting kind of a race condition, where any query you put into the template execution can’t depend on frontmatter fields which are not populated yet. In this case you need to actually insert the query as a query into the note itself.
If after creation, so that the content has been created, and there are some values within the frontmatter tags you use, you can insert the template and do the query with those current values. Now it becomes more of a task on how you want to combine the tags within your query.
So to get you started on doing such a query here is a query I ran on my test data:
tagsToMatch:: #frog, #water
```dataview
TABLE WITHOUT ID
task.tags,
this.tagsToMatch,
"<span class='" + choice(anyFlag, "cellOK", "cellWARN") + "'>" + anyFlag + "</span>" as Any,
"<span class='" + choice(allFlag, "cellOK", "cellWARN") + "'>" + allFlag + "</span>" as All,
"<span class='" + choice(noneFlag, "cellOK", "cellWARN") + "'>" + noneFlag + "</span>" as None
FLATTEN file.tasks as task
FLATTEN any(map(this.tagsToMatch, (m) => contains(task.tags, m))) as anyFlag
FLATTEN all(map(this.tagsToMatch, (m) => contains(task.tags, m))) as allFlag
FLATTEN none(map(this.tagsToMatch, (m) => contains(task.tags, m))) as noneFlag
WHERE file.folder = "ForumStuff/f57/f57484"
WHERE file.tasks AND task.tags
```
Where top part of the output is as follows:
(This also utilises some extra markup and CSS to color cells to make it easier to spot the various responses). So your result will most likely not look as colorful, and you do need to remove the WHERE file.folder ...
line for it produce any results at all for you.
The query above is a TABLE
, so to transform it back to a TASK
query, you’ll need to remove the task.
from any task references, and you don’t need some of the clauses related to singling out the tasks. So given you want it to match all the tags, it’ll look like:
```dataview
TASK
FLATTEN all(map(this.tagsToMatch, (m) => contains(tags, m))) as allFlag
WHERE file.folder = "ForumStuff/f57/f57484"
WHERE tags and allFlag
```
( You’d still need to remove the WHERE file.folder ...
line, and if you want to use a FROM
line instead it needs to go above the FLATTEN
line.
Or you could potentially move the entire expression from FLATTEN
directly instead of the allFlag
use in the last line. Play around with it, until you get a feel for what the alternate options does)
In summary, if your template is run at creation of the new file it can’t reference any frontmatter tags which hasn’t gotten a value yet. And since the query is executed at template insertion time, that is that. In this case, you need to insert the query into your note, to await the entry of values into the tags to match.
If on the other hand, you insert the template after the tags has been populated with something, you still need to find the proper query to use for which I gave some option in the query above. And even now the query result will be that of the insertion time of the template.