Greetings,
this is a “reboot” of this other closed discussion, because I had the possibility to review/test it only today.
Use case or problem
Right now, I am using Obsidian v1.4.13 on Ubuntu. I (and I guess many others) would really like to:
- Create a new note, from a template whose frontmatter includes an empty “wanted_tags” field
- type in that field any combination of tags, e.g. “linux, debian”
- call a templater that reads wanted_tags, and outputs in the note a plain markdown list of all the notes with any one of those tags in their frontmatter, and their aliases
I know how to do (1) and I already have, thanks to this forum, this templater that does exactly what I need if I hardcode one constant tag in the templater itself:
<%*
const dv = this.app.plugins.plugins["dataview"].api;
const query = 'LIST aliases FROM #obsidian WHERE aliases SORT file.mtime DESC';
const result = await dv.queryMarkdown(query);
if ( result.successful ) {
tR += result.value
} else {
tR += "~~~~\n" + result.error + "\n~~~~"
}
%>
so, what I miss, and really need help with, is what to write in the templater above, instead of “FROM all the notes tagged with #obsidian” to mean “FROM all the notes tagged with ANY of the values listed in wanted_tags”
In the original discussion @holroy kindly provided this code, but if I use it as is, nothing happens, not even a warning. And if try to “merge” it in the code above, like this:
<%*
const dv = this.app.plugins.plugins["dataview"].api;
const query = 'LIST aliases FROM []]
FLATTEN all(map(choice(typeof(this.wanted_tags) = "string",
list(this.wanted_tags),
this.wanted_tags),
(m) => econtains(file.etags, m))) as allFlag
WHERE aliases SORT file.mtime DESC';
const result = await dv.queryMarkdown(query);
if ( result.successful ) {
tR += result.value
} else {
tR += "~~~~\n" + result.error + "\n~~~~"
}
%>
I get the error shown in the screenshot. How can the templater I have be extended to accept “dynamic” tags, or combinations of them, from the frontmatter?
THANKS!