ZettelFlow API Reference
This document describes the API provided by ZettelFlow that can be used in Scripts, Hooks, and other programmable components.
Overview
The ZettelFlow API is organized into two main sections:
- Internal API (
zf.internal
): Native functionalities provided by ZettelFlow - External API (
zf.external
): Integrations with other plugins
Internal API
Vault Operations (zf.internal.vault
)
Functions for working with the Obsidian vault, files, and folders.
resolveTFolder(path: string): TFolder
Resolves a path to a folder object.
- Parameters:
path
: String path to the folder- Returns: TFolder object
- Throws: Error if the path doesn't resolve to a folder
// Example: Get a folder reference
const folder = zf.internal.vault.resolveTFolder("MyNotes/Projects");
obtainFilesFrom(folder: TFolder, extensions: string[]): TFile[]
Gets files from a folder with optional extension filtering.
- Parameters:
folder
: TFolder object to search inextensions
: (optional) Array of file extensions to filter by. Defaults to["md", "canvas"]
- Returns: Array of TFile objects sorted alphabetically by basename
// Example: Get all markdown files from a folder
const folder = zf.internal.vault.resolveTFolder("MyNotes/Projects");
const mdFiles = zf.internal.vault.obtainFilesFrom(folder, ["md"]);
User Scripts (zf.internal.user
)
User-defined scripts that are loaded from the JS library folder.
Each script is available as a function under the zf.internal.user
namespace, with the script filename (without extension) as the function name.
// Example: Call a user script named "formatDate.js"
const formattedDate = zf.internal.user.formatDate(new Date());
External API
Dataview (zf.external.dv
)
The complete Dataview API (available if the Dataview plugin is installed).
// Example: Query files using Dataview
const results = zf.external.dv.pages('#project')
.where(p => p.status !== "Complete")
.sort(p => p.priority, 'desc');
Templater (zf.external.tp
)
User scripts from the Templater plugin (available if Templater is installed).
// Example: Use a Templater user script
const result = zf.external.tp.user.myScript();
Common Context Variables
These variables are available in both Scripts and Hooks contexts:
note
Functions for working with the current note's metadata.
setTitle(title: string)
: Sets the title of the notegetTitle()
: Returns the note titlesetTargetFolder(folder: string)
: Sets the target foldergetTargetFolder()
: Returns the target folder path
content
Functions for manipulating the note's content.
add(content: string)
: Adds content to the noteget()
: Gets the current contentmodify(key: string, result: string)
: Replaces a substring with new contentaddTag(tag: string)
: Adds a tag to frontmatteraddTags(tags: string[])
: Adds multiple tags to frontmattergetTags()
: Gets all tags from frontmatteraddFrontMatter(frontmatter: Record<string, any>)
: Adds properties to frontmattergetFrontMatter()
: Gets all frontmatter properties
context
A shared object for storing state between different execution steps.
// Store data in one step
context.myData = { value: 42 };
// Use it in another step
console.log(context.myData.value); // 42
app
The Obsidian API instance for advanced operations.