What I’m trying to do
I have a bunch of queries like this in my monthly journal post that searches through that month’s daily notes for a prayer list that contains a hashtag and combines them into one list. This makes all of my prayer requests viewable in one spot every month, which is nice.
```dataviewjs
const query = `TABLE C.text AS "Prayer - Supplication - Community"
FROM "Calendar/Journal/2023/02_Feb"
FLATTEN file.lists AS L
WHERE contains(L.tags, "#🙏/Supplication/Community")
FLATTEN L.children AS C`
// executing the dataview query and return results
let DQL = await dv.tryQuery(query);
// render the table only if any value
if (DQL.values.length > 0){
dv.table(DQL.headers, DQL.values)
}
```
This works pretty well but I would like to pull it into its on js file called something like Query Prayer Requests.js
so that in my monthly note I can just have a dv.view() like:
```dataviewjs
dv.view("Query Prayer Requests", {columText: "Prayer - Supplication - Community", searchTag: "#🙏/Supplication/Community"})
```
I am having trouble pulling the text into variables, as I am not sure how to get the query to recognize them.
I am also not sure how I am going to deal with the FROM "Calendar/Journal/2023/02_Feb"
as this will change each month / year.
Things I have tried
Variables
First I pulled the strings into variables then I tried to put them into ${columText}
and ${searchTag}
. I saw somwhere the suggestion to use just the $columText
and $searchTag
. I have tried surrounding it with different quotes ` ’ " but I keep getting a syntax error.
Evaluation Error: SyntaxError: Unexpected identifier
at DataviewInlineApi.eval (plugin:dataview:18370:21)
at evalInContext (plugin:dataview:18371:7)
at asyncEvalInContext (plugin:dataview:18378:16)
at DataviewJSRenderer.render (plugin:dataview:18402:19)
at DataviewRefreshableRenderer.maybeRefresh (plugin:dataview:17980:22)
at HTMLDivElement.r (app://obsidian.md/enhance.js:1:11445)
Here is my current Query Prayer Requests.js
file that is being pulled into the dv.view()
let {columText, searchTag} = input;
let directory = "Calendar/Journal/" + moment(dv.current().file.name, 'YYYY-[M]MM').format('YYYY/MM_MMM');
const query = `TABLE C.text AS "${columText}"
FROM ${directory}$
FLATTEN file.lists AS L
WHERE contains(L.tags, "${searchTag}$")
FLATTEN L.children AS C`
// executing the dataview query and return results
let DQL = await dv.tryQuery(query);
// render the table only if any value
if (DQL.values.length > 0){
dv.table(DQL.headers, DQL.values)
}
Date
Once I get the variables situated and working, I am hoping that something like this might work for the dates.
let directory = "Calendar/Journal/" + moment(dv.current().file.name, 'YYYY-[M]MM').format('YYYY/MM_MMM')