Query FROM path to dynamic folder

I have a folder structure like this: journal/YYYY/weekly notes

What I’m trying to do

I’m making a year template that queries all the weekly notes for that year (so they are in that years folder). Issue is, I don’t know how to make the FROM query to accept a dynamic date in the path.

Things I have tried


Table title, score
From ...
WHERE score != null

I have tried with these FROMs, but all of them result in some error. It seems like I can only use the static year number.
From “journal/” AND (date.getYear())
From “journal/{{date:YYYY}}”
From “journal/” + date.getYear()
From “journal/” + {{date:YYYY}}

Remember when viewing the template the queries will not work, you need to create the note based on the template before you can check the query.

Based on this it seems like the second variant should work, that is From "journal/{{date:YYYY}}".

If you want a truly dynamic query, but depending on a template and which gets updated when the year switches, you’ll need to write your query using a WHERE clause related to file.folder.

Yes, I’m testing with a note.

This “journal/{{date:YYYY}}” doesn’t work, the note don’t get the date year replaced.

I couldn’t find a direct or native way to do it, so I just fixed it with Templater, like this:

From "journal/<% tp.date.now("YYYY") %>"

1 Like

Hmm… I’ve not used the core template plugin, but it should work there as well.

I’m usually doing stuff like that using Templater too.

It seems that u cant run template commands in a dataview query.

I think u are inquery about the created date of files, so I think it may be better to use a filter rather than a folder location:

from "Journal"
where file.cday.year = date(now).year

Or based on the specific folder name is what u need:

from "Journal"
where split(file.folder,"/")[1] = string(date(now).year)

You can use templater commands in the template used to create the note with the query. And I reckon the same should be doable with the core template plugin.

When the note is instantiated you can’t use the template commands though.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.