# How to set up org-roam-capture-templates to create a node headline?

**URL:** <https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282>\
**Category:** Troubleshooting\
**Created:** [December 17, 2021, 1:37pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282 "2021-12-17T13:37:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![thread314](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thread314](https://org-roam.discourse.group/u/thread314)\
**Post date:** [December 17, 2021, 1:37pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/1 "2021-12-17T13:37:56Z")

</div>

I’d like for my default new node creation to create a new heading with it’s own id in a target file.

I currently have set up my `org-roam-capture-templates` as such:

```auto
  (setq org-roam-capture-templates
        '(("d" "default" entry "* ${title}"
           :target (file "/home/eddie/orgnotes/org-roam.org")
           :unnarrowed t)))

```

This does set up a new heading in the target file, however the new heading is not assigned an id. Instead, the file itself is given an id (if it does not have one already).

I would like instead for the new heading to be given an id and for the link to refer to the heading (instead of the file).

How can I achieve this?

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [December 17, 2021, 7:51pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/2 "2021-12-17T19:51:11Z")

</div>

Is [this thread](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/10) of any help?

---

<div class="post-metadata">

**Author:** ![thread314](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thread314](https://org-roam.discourse.group/u/thread314)\
**Post date:** [December 18, 2021, 5:13am UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/3 "2021-12-18T05:13:57Z")

</div>

That is very close, however when I run `org-roam-node-insert` and create a new node, the link uses the id for the file, not the node.

When I run `org-roam-node-insert` on an existing node it links correctly, however.

Would there be a way to fix this issue?

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [December 18, 2021, 5:45pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/4 "2021-12-18T17:45:41Z")

</div>

I had a quick look at the current code. It does not look to be designed to work in the way you would like. The headline node is not created in time to be passed to the capture finalize function, which inserts a new ID link.

I could suggest two options:

- Code it yourself (with others’ help – I can’t see how this can be done easily)
- Create a project’s GitHub issue to request a new feature

This is only as far as I could see. Other people might have better ideas.

---

<div class="post-metadata">

**Author:** ![kjelljorner](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/kjelljorner/32/1054_2.png) [@kjelljorner](https://org-roam.discourse.group/u/kjelljorner)\
**Post date:** [December 20, 2021, 10:39am UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/5 "2021-12-20T10:39:11Z")

</div>

I set up the following to capture with the standard org-capture and the org-capture templates. The key is to create an ID automatically in the capture buffer with the hook: `:hook (org-capture-mode . org-id-get-create)`. I could not get it to work with org-roam-capture as it seems to use the ID of the file as mentioned above.

My setup.

```auto
(use-package org
  :ensure nil
  :hook (org-capture-mode . org-id-get-create)
  :bind
  ("C-c l" . org-store-link)
  ("C-c a" . org-agenda)
  ("C-c c" . org-capture)
  :config
  (setq org-startup-indented t)
  (setq org-directory "~/iCloud/org"
    org-default-notes-file (concat org-directory "/notes.org"))
    (let ((capture_template (concat
                             "* %?\n"
                             ":PROPERTIES:\n"
                             ":DIR: %^{DIR|attachments|../../Privat|../../Arbete}\n"
                             ":END:\n"
                             )
                            ))
      (setq org-capture-templates `(
                                    ("p" "Private" entry (file "private.org") ,capture_template
                                     :empty-lines 1)
                                    ("w" "Work" entry (file "work.org") ,capture_template
                                     :empty-lines 1)
                                    )
            )
      )
    )

(use-package org-roam
  :ensure t
  :custom
  (org-roam-directory (file-truename org-directory))
  :bind (("C-c n l" . org-roam-buffer-toggle)
         ("C-c n f" . org-roam-node-find)
         ("C-c n g" . org-roam-graph)
         ("C-c n i" . org-roam-node-insert)
         ("C-c n c" . org-roam-capture)
         ("C-c n j" . org-roam-dailies-capture-today))
  :config
  (org-roam-db-autosync-mode)
  )

```

---

<div class="post-metadata">

**Author:** ![thread314](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thread314](https://org-roam.discourse.group/u/thread314)\
**Post date:** [December 20, 2021, 1:14pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/6 "2021-12-20T13:14:05Z")

</div>

> [@](#):
>
> create an ID automatically in the capture buffer with the hook

Huh, that’s a good idea. That’ll create an id from org-capture, but `org-roam-node-insert` still links to the file, not the heading.

> [@](#):
>
> - Create a project’s GitHub issue to request a new feature

I suspect this may be what I need to do - I’ll post back here when I do.

---

<div class="post-metadata">

**Author:** ![kjelljorner](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/kjelljorner/32/1054_2.png) [@kjelljorner](https://org-roam.discourse.group/u/kjelljorner)\
**Post date:** [December 20, 2021, 1:43pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/7 "2021-12-20T13:43:47Z")

</div>

> [@thread314](#):
>
> but `org-roam-node-insert` still links to the file, not the heading.

At least for me it links to the node in question, but maybe that’s because I don’t have any ID for the file.

---

<div class="post-metadata">

**Author:** ![thread314](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thread314](https://org-roam.discourse.group/u/thread314)\
**Post date:** [December 21, 2021, 11:12pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/8 "2021-12-21T23:12:48Z")

</div>

> [@](#):
>
> At least for me it links to the node in question, but maybe that’s because I don’t have any ID for the file.

Odd, for me it just seems to link the first id tag it comes across in the file.

No matter, the hook strategy also creates an id tag for all my captures, which I don’t like.

I think I’ll just stop trying to fight the package and just have all my org nodes be files. Thanks for the tips/help.

---

<div class="post-metadata">

**Author:** ![nom](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@nom](https://org-roam.discourse.group/u/nom)\
**Post date:** [January 15, 2022, 6:07pm UTC](https://org-roam.discourse.group/t/how-to-set-up-org-roam-capture-templates-to-create-a-node-headline/2282/9 "2022-01-15T18:07:15Z")

</div>

I use `org-capture-prepare-finalize-hook` for this:

```auto
(defun nom/org-roam-capture-create-id ()
  "Create id for captured note and add it to org-roam-capture-template." 
  (when (and (not org-note-abort)
             (org-roam-capture-p))
    (org-roam-capture--put :id (org-id-get-create))))
(add-hook 'org-capture-prepare-finalize-hook 'nom/org-roam-capture-create-id))

```
