How do capture templates work?

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.

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

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).

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.

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?

I think you will benefit from this link: Streamlined custom capture for tasks and notes

It’s from another thread

Thanks, @Kot-behemoth :slight_smile:

1 Like

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