Hi all,
Recent Obsidian convert. I’ve been trying to create Templater templates where the related
frontmatter property is automatically populated with a link to the folder note of the parent folder.
For example, if I create the new note:
/01.Action items/TODO.md
… then the frontmatter for this new note should contain:
related: [[/01.Action items/01.Action items.md]]
… where 01.Action items.md
is a note I have created previously
Things I’ve tried
With considerable help from the @AlanG solution on this thread, I have a partial solution:
<%*
// Add this at the end of your template file
const folders = tp.file.folder(true).split('/'); //breaks the folder path into an array
const parent = folders[folders.length - 1]; //gets the last element of the array
const foldernote = tp.file.folder(true) + "/" + parent + ".md"
// Add/remove properties from the newly created note.
// The reason for the timeout is to wait until after the new note exists in your vault.
setTimeout(() => {
// Get the path to the new file
const newFile = tp.file.find_tfile(tp.file.path(true))
// Process the frontmatter
app.fileManager.processFrontMatter(newFile, (frontmatter) => {
// Add a new field
frontmatter['category'] = 'permanentnote'
frontmatter['related'] = "[[" + foldernote + "]]"
// Or delete the properties you don't want
// delete frontmatter['Some frontmatter field']
})
}, 300)
%>
This solution creates a valid link to the folder note in the parent folder, and associates it with the related
property. However, if the path to the folder note is changed, then the link does not automatically update (as would be the case if I had created the link manually).
Is there a way that I can programmatically create links with Templater in such a way that Obsidian automatically keeps them up to date?