Configuring Property Hooks
Property hooks can be configured through the ZettelFlow settings panel. You can add, edit, and remove hooks for different frontmatter properties.
Accessing Property Hooks Settings
- Open Obsidian Settings
- Navigate to the ZettelFlow plugin settings
- Scroll down to the "Hooks" section
- Find the "Property Hooks" subsection
Adding a New Property Hook
- Click the "Add Hook" button
- Select a property from the dropdown menu (this shows all available frontmatter property types in your vault)
- Click "Add Hook" to confirm
Editing a Property Hook
Once you've added a hook, you can expand it to edit:
- Click the expand button (down arrow) on the hook
- Write your JavaScript code in the editor
- Click "Save Hook" when done
Script Environment
When writing your hook script, you have access to these variables:
event
: An object containing:request
: Information about the property changeoldValue
: The previous value of the propertynewValue
: The new value of the propertyproperty
: The name of the property that changed
file
: The TFile object representing the current file-
response
: Object where you can set new frontmatter valuesfrontmatter
: Record of property/value pairs to update/add to the frontmatterremoveProperties
: Array of properties to delete from the frontmatterflowToTrigger
: Canvas name to trigger (if applicable). It must be avaliable in the vault inside the path defined in the ZettelFlow settings panel - hooks section. It can only be initialized once and will be triggered when the all hooks are finished.
-
zf
: Access to ZettelFlow functions and utilities. For detailed documentation on all ZettelFlow API functionality, please refer to the ZettelFlow API Reference.
Saving Updated Frontmatter
To update frontmatter properties as a result of your hook, add them to the event.response.frontmatter
object:
// Example: Update a 'status' property when 'progress' reaches 100
if (event.request.property === 'progress' && event.request.newValue === 100) {
event.response.frontmatter.status = 'Complete';
}
// Always return the event object
return event;
Managing Hooks
- Reordering: Drag and drop hooks to change their execution order
- Deleting: Click the X button on a hook to remove it
- Editing: Expand a hook to edit its script