Try to understand how the templates work in org-roam-capture-templates

Hello,

While I configure my Org-roam capture templates, I fail to understand 2 points:

  • Why is there 2 templates for each entries in the variable org-roam-capture-templates
  • How to define same expansion in both templates but been only asked once for a value

In the documentation, and the doctsring of org-roam-capture-templates, it’s explained that the 4 th element of each entries is a “template used for creating the capture item”.

The docstring also say that for the option :target, if I set the value (file+head "path/to/file" "head content"), the “head content will be inserted if the node is a newly captured one”.

So why is there 2 templates ? Which one do I need to use ?

If I define the 2 templates, and add an expansion like ${Title} in each of them: During a new capture I got asked twice Title: in the mini-buffer. How can I do to be only asked once for the title ?

I have searched on the web and on this forum, but cannot found an answer to my questions.

Check this that I wrote some months ago. I think it answers some of your questions.

The :target template is only used when the file is created.

The other template (3rd parameter) is used always.

You might want to post your template, so we know what is going on.

1 Like

Thank you for your answer.

Here is my template entry:

("b" "Literature note (book or article)" plain
        (file "~/Roam/templates/literature.org")
        :target (file+head
                 "reference/%<%Y%m%d%H%M%S>-literature-${slug}.org"
                 "#+title: ${Year}, ${Author}: ${Title}\n#+filetags: :literature:\n\n")
        :empty-lines-before 2
        :unnarrowed t)

And here is the content of “~/Roam/templates/literature.org”:

* ${Title}
:PROPERTIES:
:Author:        ${Author}
:Publisher:     ${Publiser}
:Release_year:  ${Year}
:URL:           ${URL}
:END:

# If I have the numeric copy of the book, attach it

** Synopsis

%?


** Notes

# Use Org-noter if numeric book is attached

And here is the result I would obtain after a capture:

:PROPERTIES:
:ID:       6fba454a-a1c8-44da-a0db-a6037b5ed452
:END:
#+title: 2024, Mickey Petersen: Demystifying Emacs’s Window Manager
#+filetags: :literature:


* Demystifying Emacs’s Window Manager
:PROPERTIES:
:Author:        Mickey Petersen
:Publisher:     Mastering Emacs
:Release_year:  2024
:URL:           https://www.masteringemacs.org/article/demystifying-emacs-window-manager
:END:

# If I have the numeric copy of the book, attach it

** Synopsis




** Notes

# Use Org-noter if numeric book is attached

PS: I still search for a better way to do a literature notes which also contain enough information to retrieve the book or article and who work with Org-noter.

I modified my Org-roam capture template.

As each of my notes are a file, I modified the “:target” like this:

…
 :target (file "reference/%<%Y%m%d%H%M%S>-literature-${slug}.org")
…

And I added this on the top of my template file (“~/Roam/templates/literature.org”):

#+title: %^{Year}, %^{Author}: %^{Title}
#+filetags: :literature:

And finally, I replaced each ${key} with %^{key}, so I can use %\1, %\2, etc to reuse asked values.

With this, I finally have a simple literature note capture. With only one template where I define everything. Where I can have expansions for which I am asked only once for their values and where I can reuses the values multiple time in my note.

Maybe it’s not the optimal way of using Org-roam, but that what I have understand.
If I made a mistake, do note hesitate to tell me.

Take a look at this video.

This is how I add entries to my bibtex file and make org notes. I should follow your advice and make it a template. So far, I keep a file per entry.

  1. run doi-add-bibtex-entry
    It adds the paper as a reference

  2. to to org-file where you want to make the notes
    insert the citation using org-ref-cite-insert-ivy [[cite:&kudrjavets-2023-are-we]]
    or by hand. at this point you can type return and the org-ref menu appears. The hydra will give all the options without having to memorize the commands, including adding notes, adding pdf, etc.

2 Likes

oops. It looks like I never posted the URL

https://old.reddit.com/r/emacs/comments/1cbgjdh/explaining_how_orgroam_templates_work_how_to/

1 Like

The other template (3rd parameter) is used always.

What do you mean by “used always” ?

Like, every time I open the node ?