From c11b396a6262f2d468d32f5eb247e3d232c72e01 Mon Sep 17 00:00:00 2001
From: Christer Bosvik <christer.bosvik@skf.com>
Date: Mon, 18 Nov 2024 08:38:04 +0100
Subject: [PATCH 1/3] If note was prevoiusly created include it in the call

---
 lua/obsidian/templates.lua | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lua/obsidian/templates.lua b/lua/obsidian/templates.lua
index ac8a83f2..d7e9f3e7 100644
--- a/lua/obsidian/templates.lua
+++ b/lua/obsidian/templates.lua
@@ -151,12 +151,14 @@ end
 
 ---Insert a template at the given location.
 ---
----@param opts { template_name: string|obsidian.Path, client: obsidian.Client, location: { [1]: integer, [2]: integer, [3]: integer, [4]: integer } } Options.
+---@param opts { note: obsidian.Note|?, template_name: string|obsidian.Path, client: obsidian.Client, location: { [1]: integer, [2]: integer, [3]: integer, [4]: integer } } Options.
 ---
 ---@return obsidian.Note
 M.insert_template = function(opts)
   local buf, win, row, _ = unpack(opts.location)
-  local note = Note.from_buffer(buf)
+  if opts.note == nil then
+    opts.note = Note.from_buffer(buf)
+  end
 
   local template_path = resolve_template(opts.template_name, opts.client)
 
@@ -165,7 +167,7 @@ M.insert_template = function(opts)
   if template_file then
     local lines = template_file:lines()
     for line in lines do
-      local new_lines = M.substitute_template_variables(line, opts.client, note)
+      local new_lines = M.substitute_template_variables(line, opts.client, opts.note)
       if string.find(new_lines, "[\r\n]") then
         local line_start = 1
         for line_end in util.gfind(new_lines, "[\r\n]") do

From 532daa521d243ac9c8c13c746a978991e495dd72 Mon Sep 17 00:00:00 2001
From: Christer Bosvik <christer.bosvik@skf.com>
Date: Mon, 18 Nov 2024 09:26:20 +0100
Subject: [PATCH 2/3] Add the created note to opts

---
 lua/obsidian/client.lua | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lua/obsidian/client.lua b/lua/obsidian/client.lua
index 00c09c77..d0a14ddb 100644
--- a/lua/obsidian/client.lua
+++ b/lua/obsidian/client.lua
@@ -1875,6 +1875,7 @@ Client.write_note_to_buffer = function(self, note, opts)
 
   if opts.template and util.buffer_is_empty(opts.bufnr) then
     note = insert_template {
+      note = note,
       template_name = opts.template,
       client = self,
       location = util.get_active_window_cursor_location(),

From 5d3febee6f96f2bbe476323af2041e5c6feaa6f8 Mon Sep 17 00:00:00 2001
From: Christer Bosvik <christer.bosvik@skf.com>
Date: Mon, 18 Nov 2024 09:32:54 +0100
Subject: [PATCH 3/3] Update CHANGELOG.md

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b585ed0e..c409b6cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Fixed an edge case with collecting backlinks.
 - Fixed typo in `ObsidianPasteImg`'s command description
 - Fixed the case when `opts.attachments` is `nil`.
+- Fixed bug where `ObsidianNewFromTemplate` did not respect `note_id_func` (#737)
 
 ## [v3.9.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.9.0) - 2024-07-11