Dynamic Commands of Templater doesn't work in frontmatter

I’m trying to use this code:

---
creation date: <% tp.file.creation_date() %> 
update: <%+ tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>
---
# <% tp.file.title %> 

I tried also a file with:

---
creation date: <% tp.file.creation_date() %> 
update: <%+ tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>
---
# <% tp.file.title %> 

now: <%+tp.date.now()%>
<%+ tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>

And in all of these tests, the dynamic command of the templater did not work in the frontmatter but worked correctly in the body.
Am I doing something wrong?

Thank you for the support

It’s invalid YAML.
“creation date” → “creation-date”

1 Like

“Creation date” worked fine, it is the dynamic command that is not working as expected in the frontmatter:

Edit mode:

Reading mode:

UPDATE:
Thanks to other tests and a question on Reddit I reached a “solution”.
The dynamic commands can’t be embedded in the YAML file because, as metadata, they can’t be dynamic.

The solution found is to encapsulate the modified date with apostrophes in order to render the date in preview mode.
this result is fine because my goal was to “only” see the creation and last modified date in the metadata block and for querying them I can always use the Dataview native “file.ctime” and “file.mtime”.

Edit mode
creation-date: 2022-05-20 09:17
modification-date: ‘<%+ tp.file.last_modified_date(“dddd Do MMMM YYYY HH:mm:ss”) %>’

Preview mode
creation-date: 2022-05-20 09:17
modification-date: ‘Wednesday 18th May 2022 10:27:49’

I really don’t have an answer on why if you use apostrophes it works as I wanted.
Probably the string format is rendered in preview mode and the date format no.
This is actually something to look into.