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 97130e6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,32 @@ 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,
---@param note obsidian.Note
uppercase_id = function(note)
return note.id:upper()
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 97130e6

Please sign in to comment.