Automatically update YAML fields using templates

Hello,

What I am trying to do

I am running the latest public obsidian on Mac.

I am trying out Obsidian from a TiddlyWiki background. I am used to my “tiddlers” (obsidian notes) having the following fields associated with them:

title:
created:
modified:
tags:

I have been using the Templater plugin to place this YAML block on top of all of my notes (It would be great if this was automatic, but I posted about that in another topic).

I’d like to make sure I understand something about how Obsidian+Templater works. When this template is “pasted in”/“applied”, Templater will calculate these times and place them in automatically for me.

However - this is only ever done once, unless I go ahead and apply template again myself. So future modifications will not cause the modified time to be updated.

In other words, there is no way to automatically have these fields updated.

Is this correct or am I missing something simple?

3 Likes

What system are you on?

If I we’re to do this on a Mac I would use Hazel to watch for changes, then run a script when triggered that updates the text based on the file modification date.

Ive updated my post to reflect Im running on Mac. I see thanks for the suggestion. I just want to make sure this can’t be accomplished inside Obsidian itself.

Some questions:

  • Templates (core plugin) or Templater (community plugin)?
  • How do you insert the template in the note?
  • What do you mean by “automatically update YAML fields”? («automatic» fields in templates only work in the moment they’re inserted in the note)
  • You use fields like this {{date:YYYY-MM-DD}}?

Look here

File Last Modif Date: <% tp.file.last_modified_date() %>

File Last Modif Date with format: <% tp.file.last_modified_date(“dddd Do MMMM YYYY HH:mm”) %>

You should be able to make the last modified date automatically update by putting “<%+” instead of “<%” at the start of the commands.

This is extremely confusing and fiddly, but the “+” sign here indicates a dynamic command. If you have just “<%” it will immediately put in a date and that’ll never change to reflect later modifications. With the “+” though it should update itself with the last modified date every time you change to preview mode.

It kind of works, basically. For some reason it doesn’t work on mine right now, I don’t know why, I don’t have 5 hours to fuss with it. But it’s worked for me in the past, just been a couple of weeks since I messed with this stuff and I forget exactly what you have to do to get this crap to work.

Unfortunately documentation for this stuff is just a pain in the butt to sort out. But you can probably get this going if you fiddle around with it for a while.

1 Like

That’s one of the reasons for my first question: Templates or Templater.
I don’t have knowledge in Templater. But that possibility seems great.

EDIT: about refresh problems - https://silentvoid13.github.io/Templater/docs/commands/dynamic-command)

Thanks for the tips. I think I’m running into this.

To start: Templates and Templater, both turned on. I know the syntax for Templates + Templater is different, so different template files. I know the Template + Templater have different commands for ‘Insert Template’.

In my basic template, for Templater, I have:

---
creation date: <% tp.file.creation_date() %>
modification date: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>
---
[[00 index|Index]]

## <% tp.file.title %>

Which results in:


creation date: 2021-08-16 06:54
modification date: Monday 16th August 2021 06:57:10

[[00 index|Index]]

test

Great, no problem, but the modification info will never change.

If I change modification date, by adding a +


creation date: <% tp.file.creation_date() %>
modification date: <%+ tp.file.last_modified_date(“dddd Do MMMM YYYY HH:mm:ss”) %>

[[00 index|Index]]

<% tp.file.title %>

I get…


creation date: 2021-08-16 06:54
modification date: <%+ tp.file.last_modified_date(“dddd Do MMMM YYYY HH:mm:ss”) %>

[[00 index|Index]]

test

… and the modification date code is pasted.

I did look here: Dynamic Commands | Templater Maybe something simple, but with the + added to the modification date, the code is always there. Even if I close and reopen the note. Do I mis-understand the refresh problems section? Any idea what I’m doing wrong?

Yep, I’m having the same problem, maybe Dynamic Commands work only in Mac? (I’m using Obsidian on Windows)

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