Recent searches

in

FileContent

On this page

Accessed through a File's content property. Provides body-content access for a file: everything after the front matter. Additionally, you can read or replace a file's body as a string.

Type

Object

Properties

getPromise<string | undefined>#

Returns the file's body content (everything after the front matter) as a string. Resolves to undefined if the file does not exist.

Returns: A promise for the body content string.

Available on: FileContent.

Show examplesHide examples

In this example, we read the body content of the file open in the editor and log it.

JavaScript
Copied to clipboard
const content = await api.currentFile().content.get();
console.log(content);
setPromise<void>#

Replaces the file's body content with the given string. This marks the file as having unsaved changes; a Team Member must save the Site to persist it. Has no effect if the file does not exist.

Returns: A promise that resolves once the change is applied to the editor.

Parameters:

  • content string RequiredThe new body content, as a string.

Available on: FileContent.

Show examplesHide examples

In this example, we append a paragraph to the file's current body content.

JavaScript
Copied to clipboard
const file = api.currentFile();
const content = await file.content.get();
await file.content.set(`${content}\n\nAppended paragraph.`);
Open in a new tab