obsidian-developer-docs icon indicating copy to clipboard operation
obsidian-developer-docs copied to clipboard

Should there be a sample for processFrontMatter?

Open YousufSSyed opened this issue 2 years ago • 0 comments

https://docs.obsidian.md/Reference/TypeScript+API/filemanager/processFrontMatter

On the page its not clear how exactly to read or write property values with it. I think this code sample might help

// get the current file and check if the "Date Completed" property is blank (but also present). If so then set it to the current time with MomentJS
let file = app.workspace.getActiveFile();
await app.fileManager.processFrontMatter(file, (fm) => {
    if (fm["Date Completed"] === null) {
        fm["Date Completed"]  = moment().format("YYYY-MM-DD");
    }
});

YousufSSyed avatar Nov 10 '23 23:11 YousufSSyed