I found coding which allows me to rename a note with the title “Untitled” and pasted it into the template. I want to also be able to add information to some frontmatter fields in the same way when creating a note from a template. I am just too new to this to figure it out on my own, so I am hoping someone will/can help me.
This is my template:
<%*
let title = tp.file.title
if (title.startsWith(“Untitled”)) {
title = await tp.system.prompt(“Title”);
await tp.file.rename(title);
}
tR += “—”
%>
title: <%* tR += title %>
created: <% tp.date.now(“YYYMMDDHHmm”) %>
tags:
source:
author:
type:
quote:
paraphrase:
<%* tR +=“—” %>
<%* tR += title %>
The items I would to which I would like to add information when I am changing the name of the title are: tags, author, type, quote (eg. “Y”,“N”,“M”), and paraphrase (eg. “Y”,“N”,“M”). I wouldn’t always be adding information to all of them , so I need to be able to skip fields.
Don’t know if you got any further with this but I’m working on something similar in the gist below.
For some reason, it doesn’t want to preview the whole thing from my gist.
Total newbie question - do all of the scripts (eg mutute.frontmatter.js) go in the same template ?? Do they reside in a different file ? And i assume each script is preceeded by the ```dataviewjs characters…
Thanks and much appreciated !
Not quite. These are “user scripts” for Templater, not dataviewjs, so no tick symbols or dataviewjs: instead they go in separate Javascript (.js) files. I believe that .js files should only ever have 1 module.exports in them. So the content in the post above yours would go in a file called mutate_frontmatter.js in your folder for user scripts that you’ve specified in the Templater settings tab. Note that you’ll need to create (or at least rename) this mutate_frontmatter.js file outside Obsidian so that it has the correct file extension - Obsidian puts a .md at the end of all files it creates.
The file that calls the script such as in two posts above yours is just any file in Obsidian.
Note: How did I know what name to call the .js file, with the _ and everything? The first line of the file that calls the script has it, which I’ve bolded in the quote below: