Template tells me to create a file that already exists? Why? See screenshot

Things I have tried

I have tried just about everything I could think of.

  • I have now turned on the core Templates plugin, and turned off Templater → I get this problem. (current sitution)

  • I have turned on Templater, and turned off the core Templates plugin → I get this problem.

  • I have turned them both on: I get this problem.

  • I have turned them both off → of course I get nothing, duh…

  • I have used the core Daily Notes plugin with all of the above options and restarted Obsidian after every change I made to settings and templates.

  • I have used the Periodic Notes, idem.

  • I have had my Periodic notes in the root, in a folder with and without an icon in front of the folder name, I have made separate folders for year/month/week/days and i have thrown everything in the same folder…

What I’m trying to do

THE PROBLEM

The templates generates the right file (in all of the above mentioned situations) with links that keep telling me the file it links to does not exist BUT IT DOES.

WHY oh why is this happening? I must be missing something, that is totally obvious to anyone but me :smirk:

1 Like

Thanks for sharing such a clear writeup of the things you tried!!!
I am surprised it gave you that error even when the notes were in the root of the vault!
All of my daily notes live in a folder called “days” so if I were writing that template a line would look like this:

[[days/{{monday:YYYY-MM-DD}}|{{monday:dddd DD MMMMM}}]]

This may be related to the “New link format” setting on the “Files & Links” settings tab. Mine is set to “Absolute path in vault” because it is easy for my way of thinking about links. (Is it in the root? Nope, then what folder?) If yours is set to something different, do your links match the logic of your setting?

Fun fact: the {{monday:format}} notation comes from @liam's fantastic work, so it should be available if you have either Periodic Notes installed or some other plugin that uses liam’s work. It will work with either Templates or Templater (but I recommend against using both and as you found it doesn’t work if you have neither!).

Good luck!

1 Like

I had that new links setting set up differently than you (shortest path) but now changed it to what you have and restarted Obsidian (again…)and then changed the template to reflect the folder 01. PLANNING in which my Periodic Notes live. I had high hopes…but no.still doesn’t work.

Should I really need to create separate folders for days/weeks/months, so I can set folder templates? It shouldn’t matter really, should it?

1 Like

No, no it shouldn’t matter at all! My “days” folder might have weeks and months in it too. The name should not matter at all.

I’m trying to guess at a translation of the message it is giving you, so apologies if I guess wrong: (and back up anything in your 2022-06-27 file before doing this!) If you do “click on it to make it” what does it open? The existing file? A new file in the same folder? A new file in a different folder?

EDIT: @FiekeB Are the day links in your heading row at the top also giving the same error message?

1 Like

As a last resort, I decided to create an empty new vault, with just 3 plugins: Calendar, Periodic Notes and Templater. At first that also didn’t work. But now all of a sudden it does.

I have two folders: 01. PLANNING and Templates.
I have new links set to absolute path in vault, but it now also works with shortest path.
I have a relatively empty template for Daily Notes because it doesn’t matter what’s in there, it’s about the links TO the dailies FROM the weekly.
I have a weekly template, with the links formatted like [[{{monday:YYYY-MM-DD}}|{{monday:dddd DD MMMM}}]] so no folder indication the way you do it (I was planning on doing that later but it already works somehow…)
In Periodic Notes, I have daily notes linked to the daily template and the folder 01. PLANNING, and the weekly notes to the weekly template and also folder 01. PLANNING
In Templater, I have pointed it to the Templates location and turned on Trigger templates at new file creation, folder templates (which I don’t use in this scenario) and enabled user functions (which I also not use in this scenario, but it was off in the other vault…)

With this setup, I can now simply click in the calendar to create dailies and weeklies and somehow they now play nice together…all the generated links work…

…beats me bigtime why it doesn’t work in my other vault. I have heaps of plugins in there, but I already tried turning those all off apart from the 3 I need and that made no difference.

Will now try to replicate all the settings etc in my other vault where I need this behaviour for real. Will turn off all plugins again apart from the 3 I need. Will move the Templates folder to the root again, although it should not make a difference where that is located, as long as you point the plugins to the right folder. Hopefully it will start working there now, too :slight_smile:

The only other differences are that in this new testing vault I made, I use the out-of-the-box standard theme and not Minimalist, which I use in the other (real) vault. And I have turned on the Templater User Functions.

Wow! Well, I’m glad it worked. I am totally confused.

Yeah, maybe Obsidian is smart enough that if you have only one file with that name in your vault the folder indication is unnecessary. This is good for me to know, thanks!

The first one of those is the most likely to be important to your wider Obsidian use.
(FYI: User functions: you would know if you needed them turned on because they exist in .js files (which of course you have to open somewhere that isn’t Obsidian). I use this “advanced functionality” to with a one-line JS file that allows me to not write the triple-backticks for codeblocks directly in my template, meaning the various tasks query, dataview, etc. code is all visible when I open the template. Silly, but makes my life a little easier. :smiley: )

Correct, it should not matter at all! I don’t use the Calendar plugin, so I don’t know what it expects in its settings, but I assume that it is customizable just like Periodic Notes.

I am very confused and I hope you can get it working!

1 Like

In the real vault, I have now switched to the standard theme, turned off all the other plugins, replicated every setting I use in the testing vault and now it works!!!

Finding the culprit is my next mission. I will update as I go along. I will restart Obsidian and recreate the daily and weekly note after every change.

  • back to Minimalist theme → still works
  • turned on Minimalist Theme Settings → still works
  • turned on style Settings → still works
  • turned on Tasks → still works
  • turned on Advanced Tables → still works
  • turned on Customizable Sidebar → still works
  • turned on Dataview → still works
  • turned on Find and Replace in Content → still works
  • turned on Dynamic Table of Contents - > still works
  • turned on Hover Editor-> still works
  • turned on Icon Folder-> still works
  • put a folder icon in front of the 1. PLANNING folder, didn’t change the template → still works
  • put a folder icon in front of the Templates folder → still works
  • turned on Icons → still works
  • turned on Markdown Formatting Assistant → still works
  • turned on Markdown Table Editor → still works
  • turned on Natural Language Dates → still works
  • turned on Outliner → still works
  • turned on Paste URL into Selection → still works
  • turned on Tags Wrangler → still works
  • turned on Buttons → still works
  • turned on Contextual Typography → still works.

@scholarInTraining - there are no more plugins (that I use at this moment) to turn on. It somehow started working after setting up a testing vault in which it somehow just worked. The only difference was, in hindsight, that I turned on the Templater User Functions in that testing vault, and that was not on in the real vault. But in the real vault it didn’t “just” start working after turning Templater User Functions on, not even after restarting Obsidian and recreating the weekly and daily. It only started working after turning off all plugins that I used and then turning them back on again, one by one.

So it still beats me what the cause was of Templater not working before. In any vault.

Why would it make a difference if Templater User Functions are off?

1 Like

@scholarInTraining - The message it was giving me said basically, that the linked file didn’t exist and it asked if I wanted to create it. Of course I have tried that, and it just generates an empty file with the same title as my daily note for that day. So then I had two files with the same name, one empty, one the real daily note.

Now that the whole shebang works, when some daily note that is linked isn’t yet created by me by clicking in the calendar, it says the same: do you want to create this non existing file. But now, when I click in the calendar, it creates the daily and also updates the weekly and makes it link to the right, just created daily note. If I try creating that daily note by clicking in the weekly, it still generates a blank file with the same name as the daily for that day.

I find this very confusing. Perhaps it is possible to write code that instructs the template to use my DailyNote template to generate that non-existing daily note.

So this link [[{{sunday:YYYY-MM-DD}}|{{sunday:dddd DD MMMM}}]] in my weekly template, becomes [[2022-07-03|zondag 03 juli]] in my generated weekly and if the daily for that Sunday 03 July does not yet exist, I can click in the weekly note and it does generate a file with the right name, but it just does not use the daily template to do so. And I don’t know how to “tell” that link, that it should use the daily template. I don’t even know if there is code for that.

@FiekeB I am baffled but I am so glad you got it working!

In the same folder?! I didn’t think that was possible!

Yes, and that is a cool feature of the Calendar plugin! I may have to look into that plugin. I think there are probably several ways to mimic it if you open the daily note from the weekly note rather than the calendar. The most straightforward one I can think of is not 100% automatic but pretty close: use the “Templater Hotkeys” feature in the “Templater” settings tab to set up a hotkey for your “DailyNote” template, then press that hotkey if you open a daily note and it is blank. Would that work for you?

Hiding this last comment to make sure the hotkey suggestion above is easy to see:

That makes no sense to me. You would know if you were using a .js file in your templates and I can’t think of any reason why interaction between your multiple plugins would reference that code either. To my thinking, it seems much more likely that the turning off and then back on of all the other plugins was the actual fix but who knows what or where. I think this one might remain a mystery.

That does work indeed, BUT it puts that file in the root and not in 01. PLANNNING and also, that note does not get reflected with a dot on the Calendar, to indicate that it has been created. Perhaps because it wasn’t Calendar that created it. So that wouldn’t be handy

.

Ah, so Obsidian is smart about not needing the folder/ full path for a link if a note already exists, but not if it doesn’t exist. That makes sense to me! EDIT: You might be able to use “relative paths” in that setting where I have “absolute paths” to help with this wrong folder issue? But I am not sure - the setting does not give me enough information about what it does.

I am not familiar with Calendar but I certainly wouldn’t expect it to make a dot for a note in the wrong folder!

@scholarInTraining

now the whole thing works for my weekly template, that I have edited to having only this in it:

### **[[{{date:YYYY}}-W{{date:ww}}|W{{date:ww}}]]** | ma [[{{monday:YYYY-MM-DD}}|{{monday:DD}}]] | di [[{{tuesday:YYYY-MM-DD}}|{{tuesday:DD}}]] | wo [[{{wednesday:YYYY-MM-DD}}|{{wednesday:DD}}]] | do [[{{thursday:YYYY-MM-DD}}|{{thursday:DD}}]] | vr [[{{friday:YYYY-MM-DD}}|{{friday:DD}}]] | za [[{{saturday:YYYY-MM-DD}}|{{saturday:DD}}]] | zo [[{{sunday:YYYY-MM-DD}}|{{sunday:DD}}]] ^{{date:YYYYMM}}w{{date:ww}}

and that gives me a beautiful navigation bar that actually works - but ONLY from the weekly template.

I want that part in my daily template so I can easily navigate through the dailies of that week.

So I figured, let’s copy that whole code block and paste it into my daily template. Should work, right? Well, no.

So I created a new Daily Template, identical to the weekly template. Assigned it in Periodic Notes to create the Dailies. And it does…but it just doesn’t parse the dates. All I get is the same code that is in the template. Can’t figure out for the life of me why it would parse the dates while creating weeklies and refuses to do so for the dailies - with an identical template.

If I change the daily template to something basic like

WEEK - [[<% tp.date.now(“GGGG-[W]ww”, 0, tp.file.title, “YYYY-MM-DD”) %>]]

and this is - afaik - valid templater code…it gives me an error, says that it cannot parse it and tells me to check the console.

Found the console and it had error messages:

Template parsing error, aborting. 
 Bad template syntax

Invalid or unexpected token
===========================
var tR='',__l,__lP,include=E.include.bind(E),includeFile=E.includeFile.bind(E)
function layout(p,d){__l=p;__lP=d}
const _prs = [];
tR+='WEEK - [['
_prs.push(tp.date.now(“GGGG-[W]ww”, 0, tp.file.title, “YYYY-MM-DD”));
tR+='rJ2KqXzxQg'
tR+=']]'
const _rst = await Promise.all(_prs);
tR = tR.replace(/rJ2KqXzxQg/g, () => _rst.shift());
if(__l)tR=await includeFile(__l,Object.assign(tp,{body:tR},__lP))
if(cb){cb(null,tR)} return tR

```

But that message means nothing to me.

Yes, the {{monday:...}} helpers are only supported in weekly Periodic/Calendar notes. This is documented somewhere in GitHub on one of @liam 's projects, and if I find it again I will add the link.

So yes, your strategy of using the Templater tp.date.now and doing math or showing different formats seems like the way to go. As for the error message, it tells me nothing either. :frowning:

I took your code and typed it into my daily note and it resolved fine! (Well it didn’t the first time, because I forgot quotation marks around the format argument, but you remembered those.) I could also replace the 0 with a different number and have that work, or change the format string to match how my weekly note titles are and get it to link. The only thing I can think of from looking at your post is that it looks like your quotation marks are fancier than mine. I believe the curved quotes might come from the plugin Contextual Typography: does that have a way to disable making the quotation marks fancy in situations like this? If not, can you try temporarily disabling Contextual Typography and retyping the quotation marks around both your format strings to confirm that is the problem? How annoying!

1 Like

Well I took a look at the Discord Templater Channel and dumped my question in there, too :wink: there can never be too many clever minds thinking about a problem, right?

And there I was told that this is not possible because that type of code only works from the weekly notes, like you said as well.

So some suggested using real templater code and gave me an example to start with. And that almost worked, so we chatted some more and we finally got to this code, which used the entire weekly note’s contents and included that in my daily note.

<% tp.file.include(`[[${moment().format("YYYY-[W]WW")}]]`)  %>

and that showed up beautifully. But, my rather still empty weekly template isn’t supposed to stay that empty with just links to every daily of the week. More will be added soon, and I only want that block with the linked weekdays included in my daily, not the entire weekly note.

And guess what? I figured out how to do that all by myself!!

so this:

<% tp.file.include(`[[${moment().format("YYYY-[W]WW#^{{date:YYYYMM}}w{{date:ww}}")}]]`) %>

does the trick!

#periodicnotes #templater #block-includes

1 Like

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