Templater
Templater copied to clipboard
frontmatter not picking up the value of the defined field.
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?
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
This has come up a few times recently. It's worth adding to the docs IMO.
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.
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.
I have the same issue on Windows 10 Pro with Obsidian v0.15.9