Question: is tp.frontmatter supposed to work as described in the documentation?
Hello everyone,
I have been experimenting with Templater in the last few days and seems like an awesome plugin. Thank you for providing and maintaining it!
If I use the example in the documentation about tp.frontmatter exactly, it yielsundefined values in my case. That is, if a I have the following template:
---
alias: myfile
note type: seedling
---
file content
File's metadata alias: <% tp.frontmatter.alias %>
Note's type: <% tp.frontmatter["note type"] %>
It yields
---
alias: myfile
note type: seedling
---
file content
File's metadata alias: undefined
Note's type: undefined
If I follow the implementation described in https://github.com/SilentVoid13/Templater/issues/449#issuecomment-1188065737 the values are replaced correctly. Is it supposed to work like described in the documentation or is it is only meant as an illustration and cannot work this way? If it is not only for illustrative purposes, what is required to make it work like described in the documentation?
The documentation describes 2 different notes: the active note and the template note.
This is the active note:
---
alias: myfile
note type: seedling
---
file content
And this is the template note:
File's metadata alias: <% tp.frontmatter.alias %>
Note's type: <% tp.frontmatter["note type"] %>
If you apply that template to that active note, then the end result of the file will be:
---
alias: myfile
note type: seedling
---
file content
File's metadata alias: myfile
Note's type: seedling
As it's described in the documentation, it works as expected. If you want to reuse values within a template, I recommend you store the values in variables and reuse them. For example:
<%*
let alias = "myfile";
let noteType = "seedling";
-%>
---
alias: <% alias %>
note type: <% noteType %>
---
File's metadata alias: <% alias %>
Note's type: <% noteType %>
I have had the same doubt reading the documentation: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/frontmatter-module.html
After seeing some undefined I thought this plugin wasn't compatible with the new file properties, luckily I found this issue.
Just to give you my use-case: I wanted to have already defined properties in my template so every time I create a new note from my template I already have properties with default values that I could later change.
Dunno if it is helpful for any new feature, documentation adjustment or consideration.
Thank you for your work anyway 👍🏼