Skip to content
Martin Edström edited this page Jul 15, 2025 · 1 revision

Tricks

To reuse the title or ID in the template text, the following constructs are available:

  • %(org-capture-get :title), cognate to Org-roam ${title}
  • %(org-capture-get :id), cognate to Org-roam ${id}

Custom capture target

If you wish to tinker with the org-node-capture-target function, it may help to see a dumber variant of the definition, shown below.

It illustrates some limitations from the fact that Org-node stays with the vanilla Org-capture system, instead of wrapping around it as Org-roam does.

(defun my-capture-target-dumb ()
  "Experimental variant of `org-node-capture-target'.
Does not insert any text when creating a new file-level node to capture
into, instead leaving it up to the capture template itself, which MUST
include the substring %\(org-capture-get :title\), cognate to Org-roam's
${title} construct.

It must also assign an ID either via the direct substring
%\(org-capture-get :id\), or programmatically adding it at
:prepare-finalize or :before-finalize based on the value of
evaluating \(org-capture-get :id 'local\).

Note that unlike Org-roam, vanilla Org-capture has no equivalent to
:if-new, so this probably cannot behave as you want when capturing
into a pre-existing node."
  (org-node-cache-ensure)
  (apply #'org-capture-put (org-node--infer-title-etc))
  (if-let* ((node (org-capture-get :existing-node)))
      (progn
        (org-node--goto node t)
        (when (eq (org-capture-get :type) 'plain)
          (if (org-capture-get :prepend)
	      (org-node-full-end-of-meta-data)
            (outline-next-heading))))
    (org-node--pop-to-fresh-file-buffer (org-capture-get :title))))

(setq org-capture-templates
      '(("t" "Test")
        ;; A simple template that does not use `org-node-creation-hook' at all,
        ;; thus ID must be placed manually.
        ("t1" "Test: Dumb capture 1"
         entry (function my-capture-target-dumb)
         "* %(org-capture-get :title)
:PROPERTIES:
:ID:       %(org-capture-get :id)
:END:
%?")
        ;; A template that runs `org-node-creation-hook'.
        ;; NOTE: User must place `point' under the heading that's meant to
        ;;       get an ID, before finalizing with C-c C-c!
        ("t2" "Test: Dumb capture 2"
         plain (function my-capture-target-dumb)
         "Some front matter before the actual node
* %(org-capture-get :title) %?
** A subheading which should not get an ID"
         :before-finalize (lambda ()
                            (org-entry-put nil "ID" (org-capture-get :id 'local))
                            (run-hooks 'org-node-creation-hook)))))
Clone this wiki locally