I am trying to do what I think the O.P. wanted in this thread.
My goal is to have an org-roam-capture-template
prompt for a named value and reuse this value in different locations during template creation.
So far, I could successfully achieve that using org-template
prompts, and %\\1
to reuse the value somewhere else.
The following example works fine: %\\1
in the #+filetags:
part gets replaced by the bar
value passed to the FOO
property prompt.
(setq! org-roam-capture-templates '(
("n" "Note" plain "%?"
:target (file+head "areas/%<%Y%m%d%H%M%S>-${slug}.org"
"
:PROPERTIES:
:ID: ${id}
:FOO: %^{bar}
:END:
#+title: ${title}
#+filetags: :%\\1:")
)
))
Please note that I am setting additional properties in the ’head’ part because, if I use the ’body’ part of the template, I end up with two property drawers. Several threads on the forum address this issue, but I lost track, so, sorry for not giving credit.
The downside of using this approach is that values cannot be shared between the ’body’ part (%?
in the example above), and the ’head’ part.
Browsing the forum, I finally found the thread mentionned at the beginning of this post. At the end of that post, nobiot (whom I believe is also the author of org-roam
, so thanks a ton while I am at it) gave a different approach to the problem:
(defvar var "")
(setq org-roam-capture-templates
'(("s" "special" plain ""
:target
(file+head "./${id}.org" "
#+title: ${title}
#+author: %(identity var)
#+id: ${id}
This is a template %(identity var)
"))))
(let ((var (read-string "Author: ")))
(org-roam-capture nil "s"))
I would really like to replicate this approach because for what I gather from the read-string
documentation, I could pass it a list of default values. That would help me reduce the numbers of templates in my config.
Unfortunately, I am new to (doom-)emacs and I struggle with elisp
so I tried to modify it as follows.
(defvar bar "")
(setq! org-roam-capture-templates '(
("n" "Note" plain "%?"
:target (file+head "areas/%<%Y%m%d%H%M%S>-${slug}.org"
"
:PROPERTIES:
:ID: ${id}
:FOO: %(bar)
:END:
#+title: ${title}
#+filetags: :%(bar):")
)
))
(let ((bar (read-string "Foo: ")))
(org-roam-capture nil "n"))
With this in my config, the let
statement at the end gets executed when reloading or starting up Doom-Emacs, and I have no idea how to make it work.
I know it is more an elisp
issue than an org-roam
issue but this code could be useful to me in many ways.
Thanks for your time.