Struggling using dates/links/queries with Templater and Dataview

What I’m trying to do

I created a weekly template (to use with Templater, Calendar, and Periodic Notes plugins). Every time I click on a week number in a Calendar it creates a new note for that week called “Wk 24-10 Mar” (as in YY-Week number Month).

1. Creating Links to all days of the week:

I’d love to list all days from that week as links to those notes: my daily notes are located in a folder called “Daily”, so I used this to extract weekday from a title and generate each of the days:

[[Daily/<%+ tp.date.weekday("YYYY-MM-DD", 0, tp.file.title, "YYYY-[W]ww") %>]]

It does retrieve the dates all correctly. But does NOT create links, since it thinks an actual path is the code, not the displayed result…
Error

How do I make turn those dates into links automatically?

2. I wanted the week number listed as a property.
It does list the date accurately, but in edit mode still shows the code… which, I think, breaks my next script…

week: <%+ tp.file.title.split(' ')[1] %>

3. In same weekly template, I am trying to have a habit tracker overview:

That’s where I use that property “week: 24-10” I was asking about in my second question.
Using Dataview table, I list this

table without id
	file.link AS "Day",
	choice(Meditation, "👍","❌") AS "Meditate",
	choice(Quote, "👍","❌") AS "Quote",
	Goals AS "🥅Gls!"
	from "Daily"
	where week = "24-10"
	sort file.name ASC

If I enter the week number manually as I do in this sample (both in each daily note property and in this weekly query) - it works. If I try to generate the numbers dynamically via same code as above or try to access the property as in “this.week” - dataview doesn’t return me any results.

How do I do this right?
Thank you so much for your help!!

Trying to understand and read more on this: it seems that the Templater doesn’t execute those functions on file creation.

Checked my settings: applying Templater on file creation checkbox is checked.
Testing: the functions without “+” don’t work neither on file creation, nor in reading view; the ones with “+” convert to dates in reading view. Links don’t work regardless, because for them it is a function, not a date.

What am I doing wrong?!
How do I get Templater to execute ANY functions on file creation?!

Thank you!!!

As you’ve discovered the <%+ variants will transform when you switch from editing modes to the reading view. There are some rumours/talk about this might be going away in a future version of Templater, and in any case this is not what you want.

Regarding how to execute Templater templates, you’ve got three options:

  • You choose to trigger the Templater: Open Insert Template modal command, and then select the template to insert
  • You choose to trigger the Templater: Replace templates in the active file command
  • Or the most common variant, to trigger Templater on new file creation or through templates connected to folders

In any of the cases stuff in <% and <%* blocks will be replaced with their corresponding output.

So try to get a grasp of how these basic variants works out, and how to use them. And when you do that, we can try help you with your weekly note template.

But do note, that if you create an entirely empty note, i.e. not from a name link, then file name will start with Untitled and then there is no tp.file.title in the form of a date. So your example doesn’t really add up either way. There is some issues as to what comes first, the hen or the egg…

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