Creating template of dataview table for specific tags

What I’m trying to do

Hi! I’m trying to create a template where it will automatically create a table showing all notes tagged with the title, listed in the order created showing the date the file was created, or last modified.

Things I have tried

This is what I have tried but it doesn’t seem to work:

table file.ctime as "Created"  
WHERE type = "note" and tag = "<% tp.file.title %>"
sort file.ctime DESC

When i do this:

table file.ctime as "Created"  
FROM #subject 
WHERE type = "note"
sort file.ctime DESC

it works, but i want the tag to autopopulate with the title of the file, but when i try it like this:

table file.ctime as "Created"  
FROM #"<% tp.file.title %>"
WHERE type = "note"
sort file.ctime DESC

it results in a parsing error

It’ll always fail when viewed as a template, but does it still fail after creating a file based on your template?

Another tip: when using a dataview query, like yours, you could use this to refer to the current file. In other words a clause like file.name = this.file.name would limit itself to file of that name.

Finally, doing tag = file.name could work in your case, as long as that is the only tag for the other files. A safer version would be to do something like: econtains(file.etags, "#" + file.name)

Bonus tip, putting a query within a daily note, could be a bad idea related to what happens if/when you want to change that query? So I’d suggest looking into dv.view(), which would give you a more flexible way of doing stuff like this, as then you could change the script and have it apply to your daily notes the next time you view them.

Final bonus tip, adding four backticks around your markdown and/or queries will make them appear nicer in a forum post.

Oops, you are right. It worked once i applied the template. Thanks for the tips!
FYI, this is the final configuration that worked for me:

table file.ctime as "Created"  
FROM #<% tp.file.title %>
WHERE type = "note"
sort file.ctime DESC

All I changed was to remove the “” around <% tp.file.title %>
Thanks!

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