Templater properties being added to the body instead of frontmatter

What I’m trying to do

I have a simple template:

---
up: 
related: 
---

And apply it to a file that already has some frontmatter:

Screenshot 2024-06-15 at 8.18.12 AM

And I get this:

Screenshot 2024-06-15 at 8.18.25 AM

Things I have tried

I’ve tried wrapping parts of it in the <% %> tags to see if it helps with merging but getting strange behavior from that right now too –– two of the dashes disappear from view and I get a syntax error when applying the template.

Screenshot 2024-06-15 at 8.22.05 AM

This seems like a simple user error or plugin conflict – anyone seen this before?

If you already have Properties in the note to which you apply the template, you’d probably need to use something similar as Zachatoo’s “Update frontmatter” snippet.

I don’t think you can “merge” YAML/Properties automatically (but I could be wrong :innocent: :sweat_smile: )

1 Like

That makes a ton of sense. I use update time on edit plugin, and it tends to get in there before I hit my template shortcut. I’ve also been trying to apply templates to existing notes, so I’ll check out this script. Thanks @Pch!

1 Like

Yeah, that did the trick. It too me a minute to understand how to initialize the properties but it’s doing the trick:

<%*
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
  frontmatter["up"] = [];
  frontmatter["related"] = [];
});
-%>

:boom:

1 Like

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