Skip to content

Commit

Permalink
doc(templates): update custom variables substitution docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cristobalgvera committed Sep 11, 2024
1 parent 122c58a commit 3116126
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,34 @@ Date created: 2023-03-01-Wed

above the cursor position.

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:
You can also define custom template substitutions with the configuration field `templates.substitutions`.

For example, to automatically substitute the template variable `{{watermark}}`, `{{yesterday}}`, `{{normalized_title}}`
when inserting a template, you could add this to your config:

```lua
{
-- other fields ...
templates = {
substitutions = {
watermark = "Obsidian.nvim",
yesterday = function()
return os.date("%Y-%m-%d", os.time() - 86400)
end
end,
---Format `id` field of `Note` to a more human-readable string.
---For an `id` "# 17823674-My-note-title", it will returns "My note title"
---@param note obsidian.Note
normalized_title = function(note)
return note.id:gsub("%d+-?", ""):gsub("-", " ")
end,
}
}
```

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

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.
Expand Down

0 comments on commit 3116126

Please sign in to comment.