Input the creation date of a note on creation in YAML frontmatter

Things I have tried

creation date: <% tp.file.creation_date(“yyyy-MM-DD HH:mm”) %>

I also tried <%, I don’t know how to make Templater dynamically enforce the date when the note is created and to apply this default template on each created note without needing to put it in again manually.

What I’m trying to do

I want to have the date of creation down to the second (minutes would be fine, though) in YAML frontmatter dynamically inserted each time ANY note is created without manually choosing it from templates.

This works for me:

  1. Create your template and give it a name, such as: new note template
  2. Add whatever YAML you want to that template, such as:
creation_date: <%"yyyy-MM-DD HH:mm") %> 
  1. In the Templater settings, assign the template folder (create a folder for templates in the directory side bar if you haven’t already done so, using whatever name you want). For example: Template folder locatation: templates
  2. In the Templater settings, enable folder templates and then click: add new
  3. In the first field, enter the folder where new notes should be saved, such as inbox (you will need to create this folder if you haven’t already done so)
  4. In the second field, enter the path and name of the file created in point (1), such as: templates/new note
  5. When you next create a new note (CMD N), Templater should create a note using the template from point (1) and put it in the folder from point (5). The date should be created for you

If you want Templater to prompt you to name the file when it is being created, use this code in the template:

  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    title = await tp.system.prompt("Title");
    await tp.file.rename(title);
  tR += "---"
title: <%* tR += title %>
creation_date: <%"yyyy-MM-DD HH:mm") %> 

If you copy from the forum and paste into Obsidian, choose Edit > Paste and Match Style.

Or grab the file below: (914 Bytes)

Man, I love you. This was just the thing I needed. Explained so well!

1 Like

Only notes created for “000 Inbox” seem to have the template applied. If I am viewing a note in a different folder, the note is created in that folder, and the template is not applied. Is there a workaround? Or, I should specify all folders inside which I’d like the template to be applied, or it would be better only to add expectations where it’s not, for example, inside the “100. Projects” folder.

1 Like

If you want a global default that runs on all folders:

Obsidian > Preferences > Templater > Folder Templates > Add New > and then in the first field, enter a forward slash /, and in the second field, enter the Templater template you want to use.

This template will fire in all folders unless specific templates are already applied to specific folders. For example, I have a folder for books and a Templater template for notes that relate to books. If I right click on that folder and choose new note, Templater will create a new note with the book template.

I have a separate folder for book covers and it does not have a specific Templater template applied to it. If I right click on that folder and choose new note, Templater will create a new note with whatever template has been assigned as the global template.

(Just learned this today while looking at your latest question. It would probably have been a better answer to your original question. Oops. Sorry.)

Pressing CMD N without directly interacting with a specific folder will create a new note according to this setting:

Obsidian > Preferences > Files & Links > Default location for new notes.

I use an _inbox folder as it is an easy place to see recent files and decide if they should be sorted into other folders or deleted. Not everyone likes to use a dedicated folder in this way. The joy of having choice.

My default location for new files is “Same as current file”. I would l like to have the default location for new files be the Inbox, unless it’s already in the same folder as the current file. I suppose that’s better than having the / as default and then manually putting the notes from Inbox to / once they are processed; that way, I am sure there is no fleeting hiding in my vault.

Are you able to help me on that @eightning?

I use the recent files plugin for that. I haven’t applied the inbox to notes for some reason, as it’s been fundamental to my task management for months! Gotta do it now, haha.

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