Capture template from file but only for new entries

I would love to make some structured templates for different types of notes. However, once they created, I usually want to populate a section “Notes” from this nodes.
For example, I have the following template:

          ("l" "technology" plain "* %?"
           :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" (file "templates/technology.org"))
           :target (file "%<%Y%m%d%H%M%S>-${slug}.org")
           :unnarrowed t)
          )

it would work like I wanted to, but it gives me the following error:

File 20230615134515-sandbox.org added to project /home/iamkarlson/braindb/ cache.
org-roam-capture--fill-template: Wrong type argument: char-or-string-p, (file "templates/technology.org")
Error running timer ‘org-reveal’: (wrong-type-argument number-or-marker-p nil) [2 times]

How can you define capture template in file but only if it’s a new node?

This post might help you structure the variable correctly.

You don’t use :if-new and :target at the same time. They do the same thing. :if-new is old and not to be used any more; :target replaces it. I believe the former remains only for backward compatibility.

I don’t think that these parameters address my problem. For new nodes only I want to fill some standard questions, and capture my notes at the end. For example, like a wikipedia has a “quick info” section with some basic details, and you need only one of those. Even with :target parameter only - I cannot use file based templates.

I found a solution to use files for capture template here:

("n" "note" plain
           ,(format "#+title: ${title}\n%%[%s/template/note.org]" org-roam-directory)
           :target (file "note/%<%Y%m%d%H%M%S>-${slug}.org")
           :unnarrowed t)

But if I capture twice to the same node - the same template would be added twice, and I don’t want that.

Like this? Not sure if I understand your problem correctly.

(setq org-roam-capture-templates
      '(("t" "technology" plain "** %?"                       ;; <= New notes in H2
         :target (file+head+olp "%<%Y%m%d%H%M%S>-${slug}.org" ;; <= file name
                                "(#+title: ${title})" ;; <= head (only once for file)
                                ("Notes"))            ;; <= H1
         :unnarrowed t)))

If you additionally want to get the template in a file, this works on my end:

(setq org-roam-capture-templates
      '(("t" "technology" plain (file "~/templates/technology.org") ;; <= New notes in H2
         :target (file+head+olp "%<%Y%m%d%H%M%S>-${slug}.org" ;; <= file name
                                "(#+title: ${title})" ;; <= head (only once for file)
                                ("Notes"))            ;; <= H1
         :unnarrowed t)))

~/templates/technology.org looks like this:

** This is tech notes template
%?
*** Template section 1

*** Template section 2

I want this coming from the file.

See my later post

In your later post you get template from the file for all new captures, and base template for the first file creation comes from the config, and I want exactly the opposite.

I dug a little deeper by going through the code. I don’t think this is documented, but reading the code, I have realized that you can use a function name instead of a string. So this below works. (If you are interested in where to look, it’s function org-roam-capture--fill-template).

(setq org-roam-capture-templates
      '(("t" "technology" plain "** %?" ;; <= New notes in H2
         :target (file+head+olp my/get-note-file-name ;; <= file name
                                my/get-tech-head ;; <= head (only once for file)
                                ("Note")) ;; H1
         :unnarrowed t)))

(defun my/get-note-file-name ()
  (with-temp-buffer
    (insert-file "~/Documents/temp/filename.org")
    (buffer-substring-no-properties (point-min) (point-max))))

(defun my/get-tech-head ()
  (with-temp-buffer
    (insert-file "~/Documents/temp/head.org")
    (buffer-substring-no-properties (point-min) (point-max))))

~/Documents/temp/filename.org

%<%Y%m%d%H%M%S>-${slug}.org

~/Documents/temp/head.org

#+title: ${title}
#+author: Name

* Note
:properties:
:CATEGORY: notes
:end: