Templater icon indicating copy to clipboard operation
Templater copied to clipboard

frontmatter not picking up the value of the defined field.

Open 82Kang opened this issue 2 years ago • 4 comments

I am trying the templater example for frontmatter from the documentation site.

alias: myfile note type: seedling my type: <% tp.frontmatter.alias %>

When I apply this template in a note, I am getting:

alias: myfile note type: seedling my type: undefined

And if I re-apply the template to the same note, I am getting the desired results:

alias: myfile note type: seedling my type: undefined--- alias: myfile note type: seedling my type: myfile

Is it a bug or I am not using frontmatter the right way?

82Kang avatar Apr 01 '22 09:04 82Kang

The documentation starts with a file that already has frontmatter. Then, the tp.frontmatter is applied. In other words, tp.frontmatter only works if the document already has pre-existing frontmatter to work with.

If you are using this template on a new file, there is no frontmatter to parse because there is no frontmatter yet. In the example case above, you might as well go

alias: myfile
note type: seedling
my type: myfile

Hope that helps. ~Welp

welpdx avatar May 19 '22 18:05 welpdx

This has come up a few times recently. It's worth adding to the docs IMO.

AB1908 avatar May 21 '22 16:05 AB1908

This has come up a few times recently. It's worth adding to the docs IMO.

Agreed. And I hope @SilentVoid13:

  • adds another trigger (or something) so it is synchronous and
  • do something with the cache so that we can get the updated filename, or in this case, the updated frontmatter.

welpdx avatar May 21 '22 19:05 welpdx

The documentation starts with a file that already has frontmatter. Then, the tp.frontmatter is applied. In other words, tp.frontmatter only works if the document already has pre-existing frontmatter to work with.

If you are using this template on a new file, there is no frontmatter to parse because there is no frontmatter yet. In the example case above, you might as well go

alias: myfile
note type: seedling
my type: myfile

Hope that helps. ~Welp

Thanks. I though this feature is not working in mobile, then I tried on desktop and same thing happen, undefined, it's not working, and I searched and get me to this discussion.

hanung665 avatar May 23 '22 02:05 hanung665

I have the same issue on Windows 10 Pro with Obsidian v0.15.9

ssravjee avatar Aug 21 '22 15:08 ssravjee