# How do capture templates work?

**URL:** <https://org-roam.discourse.group/t/how-do-capture-templates-work/2746>\
**Category:** Requests\
**Created:** [August 29, 2022, 11:06pm UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746 "2022-08-29T23:06:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeblow](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@joeblow](https://org-roam.discourse.group/u/joeblow)\
**Post date:** [August 29, 2022, 11:06pm UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746/1 "2022-08-29T23:06:01Z")

</div>

I’m a bit confused about switching to roam v2 capture templates from vanilla org

I noticed we need a `:target` specifier, which works similar to regular/vanilla org-capture (e.g. `(file+olp "path/to/file" ("h1" "h2"))` is valid), but then roam always behaves in the same way (asking you to choose a node), even in cases where I wouldn’t expect it to.

For example with the target above, I’d expect to be prompted for a template and not a node, because I already specified the file and node I want to capture to. In the case of `(file "path/to/file")`, I’d expect to be shown nodes in that file, rather than all nodes from all agenda files.

Am I misunderstanding or misconfiguring something? I’m trying to set up `org-roam-capture-templates`.

---

<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:** [August 30, 2022, 5:28am UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746/2 "2022-08-30T05:28:18Z")

</div>

> [@joeblow](#):
>
> In the case of `(file "path/to/file")`, I’d expect to be shown nodes in that file, rather than all nodes from all agenda files.

I think this is because Org-roam presents a list of all nodes before you select a template…

---

<div class="post-metadata">

**Author:** ![joeblow](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@joeblow](https://org-roam.discourse.group/u/joeblow)\
**Post date:** [August 31, 2022, 11:26pm UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746/3 "2022-08-31T23:26:21Z")

</div>

Thanks for your quick response! That’s part of my question, why roam presents all nodes when the config specifies a file to find nodes in (second example in my original post), or why it presents nodes at all, when the config specifies a specific node already (first example).

---

<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:** [September 1, 2022, 5:55am UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746/4 "2022-09-01T05:55:33Z")

</div>

I am not sure if I understand the intent of your question, so I may sound like repeating myself – I’ll just say what I said in a different way.

When you do `M-x org-roam-capture` or `M-x org-roam-node-find`, you have not chosen a template to use yet. So Emacs does not know the template you are going to use.

The sequence of user actions for capturing a node is like this:

1. You call `M-x org-roam-capture`
2. You select a title
3. (if there are more than templates) You select a template
4. Emacs presents the node chosen (existing or new) with the template applied
5. You edit the node and finalize it

It seems your template is designed to create a new node in a file (not sure?). You could have a template that adds to an existing node. Perhaps that’s the difference that is causing some confusion? Not sure.

Org-roam expects Step 2 first. At this stage, Emacs does not know the template you are intending to choose and thus it does not know the file specified by the template.

---

<div class="post-metadata">

**Author:** ![joeblow](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@joeblow](https://org-roam.discourse.group/u/joeblow)\
**Post date:** [September 2, 2022, 2:22pm UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746/5 "2022-09-02T14:22:50Z")

</div>

I think we agree on what the current behavior is, I guess what I’m confused about is why the capture templates are the same as the original org-capture if parts of them are ignored.

If the template specifies the file, then why not either only show targets in that file or disallow templates that specify the file?

And you’re right, roam doesn’t know which template that I’m going to choose, but then shouldn’t that part come first?

I was thinking I was missing something, because it seems like a lot to filter through _all_ roam nodes every time I want to capture something, when some things that I want to capture _always_ go to the same place (tables/inbox/etc).

Maybe there are other settings that augment this behavior?

---

<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:** [September 2, 2022, 3:40pm UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746/6 "2022-09-02T15:40:13Z")

</div>

I think you will benefit from this link: [Streamlined custom capture for tasks and notes](https://systemcrafters.net/build-a-second-brain-in-emacs/5-org-roam-hacks/#streamlined-custom-capture-for-tasks-and-notes)

It’s from another [thread](https://org-roam.discourse.group/t/org-roam-protocol-creating-nodes-instead-of-a-file/2742/3)

Thanks, @Kot-behemoth 🙂

---

<div class="post-metadata">

**Author:** ![joeblow](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@joeblow](https://org-roam.discourse.group/u/joeblow)\
**Post date:** [September 2, 2022, 9:43pm UTC](https://org-roam.discourse.group/t/how-do-capture-templates-work/2746/7 "2022-09-02T21:43:34Z")

</div>

This looks like exactly what I’m looking for, thank you!
