Skip to content

Commit 11186ba

Browse files
doc(templates): update custom variables substitution docs
1 parent 122c58a commit 11186ba

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -712,20 +712,34 @@ Date created: 2023-03-01-Wed
712712

713713
above the cursor position.
714714

715-
You can also define custom template substitutions with the configuration field `templates.substitutions`. For example, to automatically substitute the template variable `{{yesterday}}` when inserting a template, you could add this to your config:
715+
You can also define custom template substitutions with the configuration field `templates.substitutions`.
716+
717+
For example, to automatically substitute the template variable `{{watermark}}`, `{{yesterday}}`, `{{normalized_title}}`
718+
when inserting a template, you could add this to your config:
716719

717720
```lua
718721
{
719722
-- other fields ...
720723
templates = {
721724
substitutions = {
725+
watermark = "Obsidian.nvim",
722726
yesterday = function()
723727
return os.date("%Y-%m-%d", os.time() - 86400)
724-
end
728+
end,
729+
---Format `id` field of `Note` to a more human-readable string.
730+
---For an `id` "17823674-My-note-title", it will returns "My note title"
731+
---@param note obsidian.Note
732+
normalized_title = function(note)
733+
return note.id:gsub("%d+-?", ""):gsub("-", " ")
734+
end,
725735
}
726736
}
727737
```
728738

739+
> [!NOTE]
740+
> You could set substitution keys to `string` or `function`.
741+
> The `function` receives the related `Note` as the first parameter.
742+
729743
### Usage outside of a workspace or vault
730744

731745
It's possible to configure obsidian.nvim to work on individual markdown files outside of a regular workspace / Obsidian vault by configuring a "dynamic" workspace. To do so you just need to add a special workspace with a function for the `path` field (instead of a string), which should return a *parent* directory of the current buffer. This tells obsidian.nvim to use that directory as the workspace `path` and `root` (vault root) when the buffer is not located inside another fixed workspace.

0 commit comments

Comments
 (0)