# Improving org-roam capture and templates

**URL:** https://org-roam.discourse.group/t/improving-org-roam-capture-and-templates/3372
**Category:** Development
**Created:** [February 24, 2024, 11:07pm UTC](https://org-roam.discourse.group/t/improving-org-roam-capture-and-templates/3372 "2024-02-24T23:07:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dmg](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dmg](https://org-roam.discourse.group/u/dmg)
#### Post date: [February 24, 2024, 11:07pm UTC](https://org-roam.discourse.group/t/improving-org-roam-capture-and-templates/3372/1 "2024-02-24T23:07:43Z")

</div>

hi everybody,

I decided to look at the capture processing. I wanted to see if I could address the issue that the destination node is being asked for even if the template does not use it.

I ended cleaning up the code and making sure that only when a new node is needed, the user is asked for its name

> <https://github.com/dmgerman/org-roam/commit/514501e2cce206bd16f1a8e614ee8d537cd06859>
>
> Org-roam templates are used for two purposes:
> 
> \- when calling org-roam-capture, …and
> \- when visiting a node that does not exist.
> 
> This means that the name of the destination is always being queried, even if it not used
> in the template.
> 
> This patch does several things:
> 
> 1. When doing org-roam-capture, it asks for the destination only
> if the template requests it.
> 
> 2. If visiting a node that does not exist, a node is created and passed to the templates.
> 
> Perhaps more importantly, the code has been refactored and the processing of the templates has
> less cloned code. It hopefully makes it easier to maintain.
> 
> Some things to note:
> 
> \- org-roam-capture--node was incorrectly described as only not-nil during a template creation.
> That was not true. This variable is not re-entrant.
> 
> \- when visiting a node that does not exist, the user is asked for a template. The template
> might never use this node (e.g. if the destination is node)

---

<div class="post-metadata">

### Author: ![akashp](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/akashp/32/1383_2.png) [@akashp](https://org-roam.discourse.group/u/akashp)
#### Post date: [March 28, 2024, 6:07pm UTC](https://org-roam.discourse.group/t/improving-org-roam-capture-and-templates/3372/2 "2024-03-28T18:07:11Z")

</div>

Hi I am not sure what is being solved here - I dont understand the code… can you give some example as to what the bug is? Or is it a refactor for ease of maintenance?  
Thanks.

---

<div class="post-metadata">

### Author: ![dmg](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dmg](https://org-roam.discourse.group/u/dmg)
#### Post date: [April 23, 2024, 9:30pm UTC](https://org-roam.discourse.group/t/improving-org-roam-capture-and-templates/3372/3 "2024-04-23T21:30:08Z")

</div>

See here:

[https://old.reddit.com/r/emacs/comments/1cbgjdh/explaining\_how\_orgroam\_templates\_work\_how\_to/](https://old.reddit.com/r/emacs/comments/1cbgjdh/explaining_how_orgroam_templates_work_how_to/)
