From 97130e6ce2eb5352072ed38ce4508f29e4b52062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Gajardo=20Vera?= Date: Tue, 10 Sep 2024 22:41:28 -0300 Subject: [PATCH] doc(templates): update custom variables substitution docs --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d5d382b62..6d423a0b9 100644 --- a/README.md +++ b/README.md @@ -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.