I really hope someone can help, as there is likely a super simple solution for this.
Structure
So my structure, is I have individual Areas which each has Subareas, with a main note.
What works
To create these Subareas I have made a Template with Templater that is trigger with Buttons.
The Template prompts me for the name of the Area and what the new Subarea and Main Note should be.
All this works like a charm
Quite proud of that, having no coding skills
But could properly be done much cleaner, so I’m all ears.
The problem
Anyway, the problem or what I can’t figure out is after creating the Subarea (folder) and Main Note, I would like to also update the frontmatter.
Here I have a field for which area and subarea it belongs to.
I have tried using MetaEdit and Metadata Menu, but simply can’t figure it out.
Really hope someone can help
Script
<%*
//Set new names
let currentareaName = await tp.system.prompt("Current Area")
let folderName = await tp.system.prompt("New Subarea Title")
let titleName = await tp.system.prompt("New Main Note Title")
await tp.file.rename(titleName)
// Define new path
let baseFolder = "Areas"
let subFolder = "Areas - Private"
//let currentareaFolder = "Vacation"
let newFolder = `${baseFolder}/${subFolder}/${currentareaName}/${folderName}/`
// Create new folder and note, if they doesn't exist
if (!tp.file.exists(newFolder)) {
await this.app.vault.createFolder(newFolder)
}
await tp.file.move(newFolder + titleName)
%>
No idea how to do it programatically, but recently I had good success using the YAML section of the Linter community plugin. You can specify keys to be added and in what order and whether you want your arrays multiline, etc.
And of course you can specify anything at file creation with Templater.
Really that simple, my dumb ass thought that you couldn’t write anything before the frontmatter.
I did know the problem was the order - but thought it would make the YAML invalid if anything was written before. As the 3 dashes become a solid line in the template - so simply didn’t test it
Embarrassing how much time I spend on this.
Thank you both for the answers and for being so kind about it.