Is there a way to have a hotkey triggered template exclude the frontmatter in the template note?
I'm looking for a way to have the template be input through a hotkey, but not include the frontmatter.
Specifically, I'm using a dataview type thing that counts pages etc. but the template is showing up in the list. However, when I try to use the method to exclude the template from the list, by giving it the yaml key "status" with the value "exclude", this frontmatter then also shows up when the template is triggered/input.
(Note: with the dataview thing I can also use tags to exclude specific documents. However, the issue I have with that is that the tags in the frontmatter show up in preview mode which carries over when I turn them into pdf files or word files.)
Is there a way around this? Thank you!
You could add a command that removes the frontmatter after the template is inserted.
At the bottom of the template note do something like:
<%*
const file = tp.file.find_tfile(tp.file.title)
const content = tp.file.content.split("\n")
let inFrontmatter = false
const newContent = content.reduce((acc, line) => {
if (!inFrontmatter && line === "---") {
inFrontmatter = true
return acc
}
if (inFrontmatter) {
if (line === "---")
{
InFrontmatter = false
}
return acc
}
acc.concat(line)
return acc
},"")
await app.vault.modify(file, newContent)
%>
@shabegom Hmm strange, this solution doesn't work anymore.
<%* const file = tp.file.find_tfile(tp.file.title) const content = tp.file.content.split("\n") let inFrontmatter = false const newContent = content.reduce((acc, line) => { if (!inFrontmatter && line === "---") { inFrontmatter = true return acc } if (inFrontmatter) { if (line === "---") { InFrontmatter = false } return acc } acc.concat(line) return acc },"") await app.vault.modify(file, newContent) %>
Hmm strange, this solution doesn't work anymore.
How does it fail? what error appears in the console?