How to update the frontmatter to add a complete date in frontmatter in a finished? #1242
-
hello, I am trying to add a complete date when I finish a note, which already have some frontmatter in it. for example, when I finished a note like
I found a template snippet which can add
The snippets I found from https://zachyoung.dev/posts/templater-snippets#suggester-for-files-in-a-specific-folder is like below:
Questions:
I know a very little template, I made some changes, but it does not work. Please help. Thanks. What I made: (does not work :-( )
Honesty, I do not understand the meaning of Thanks in advance, Sincerely, FH |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Howdy! In it's simplest form, in the If you want to set the value for a frontmatter key or add a new key/value pair, you use the <%*
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
// Add or set the value
frontmatter["key"] = "value";
// Delete a key/value pair
delete frontmatter["key"];
});
-%>
Assuming you want it to be "today", you can use <%*
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter["completed date"] = tp.date.now("YYYY-MM-DD");
});
-%>
Yes! We can use an if else statement to conditionally set <%*
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
if (frontmatter["review count"] === undefined) {
frontmatter["review count"] = 0;
} else {
frontmatter["review count"] += 1;
}
});
-%> |
Beta Was this translation helpful? Give feedback.
-
Many thanks @Zachatoo With the help, I made the templater as bellow, the date works well, and the review count( I made it to reviewedTimes) works well, too. Now, I would like to add an if clause to judge unfortunately, it does not work. Will you please have look at it and correct it, to make it works? Many thanks. The templater is shown below:
BTW, after implying the templater, I have to use clt+Z to make the Yaml shown. I really do not know why. Best Regards, FH |
Beta Was this translation helpful? Give feedback.
The syntax error is because of this section.
If you're using
else
, you cannot add a condition after it in parenthesis. You have to useelse if
instead.Or just else, without a condition.
Relevant docs.