Skip to content

FileManager.processFrontMatter method

FileManager › processFrontMatter

Official

Atomically read, modify, and save the frontmatter of a note. The frontmatter is passed in as a JS object, and should be mutated directly to achieve the desired result.

Remember to handle errors thrown by this method.

Signature:

processFrontMatter(file: TFile, fn: (frontmatter: unknown) => void, options?: DataWriteOptions | undefined): Promise<void>

Parameters:

Parameter Type Description
file TFile the file to be modified. Must be a Markdown file.
fn (frontmatter: unknown) => void a callback function which mutates the frontmatter object synchronously.
options? DataWriteOptions | undefined write options.

Returns: Promise<void>A promise that resolves when the frontmatter is processed and saved.

Since: 1.4.4

Example:

await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter['key1'] = value;
delete frontmatter['key2'];
});