Templater keyboard shortcut not handling date formula

What I’m trying to do

I have the Templater community plugin installed. I’ve created a new note template that has a simple date formula inserted into some text e.g. Created on {{date}}.
When I ⌘-P and then navigate to the new note template it creates the text with the correct date formula inserted as expected e.g. Created on 2023-08-25
I wanted to create a keyboard shortcut to save time so in the Templater settings I created a hotkey to invoke the new note template. The hotkey works but when the template is inserted the date formula is not converted and the text reads: Created on {{date}}.
I feel like I’m possibly not throwing a necessary switch in the Templater settings but can’t figure out what I’m missing.

Things I have tried

I have a question :blush: :

Are you sure, when you hit + P to trigger the command palette, you select the command :

Templater: Open Insert Template modal

and not :

Templates: Insert template


I’m asking because the {{date}} syntax is the one used by the Templates core plugin.

AFAIK, Templater won’t be able to do anything with {{date}} but the Templates core plugin can :blush:.

So, when testing your template, if you chose a command tied to the Templates core plugin, it might explain why it worked as expected… but also why, Templater, after assigning the hotkey to that template returns {{Date}} instead of the current date …

For your template to work with Templater, you could use something like :

Created on <% tp.file.creation_date("YYYY-MM-DD") %>

Where <% tp.file.creation_date("YYYY-MM-DD") %> will retrieve the creation date of the file in which you insert the template and format the date as YYYY-MM-DD.

Thanks so much! You rightly guessed what I was doing wrong. I’ve changed the code in the New Note Template to

Created on <% tp.file.creation_date() %>

and now the shortcut is working correctly as properly used through Templater and not Templates.

Much appreciated!

1 Like

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