# Nested Capture keys

**URL:** <https://org-roam.discourse.group/t/nested-capture-keys/2399>\
**Category:** Requests\
**Created:** [January 24, 2022, 12:47pm UTC](https://org-roam.discourse.group/t/nested-capture-keys/2399 "2022-01-24T12:47:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbd](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@tbd](https://org-roam.discourse.group/u/tbd)\
**Post date:** [January 24, 2022, 12:47pm UTC](https://org-roam.discourse.group/t/nested-capture-keys/2399/1 "2022-01-24T12:47:33Z")

</div>

Is it possible to have nested capture keys? for example, if you want to create a capture template for programming (p): python(pp), c(pc), ruby (pr), etc. I know this can be done in orgmode but not sure if it is possible for org-roam.

Thanks

---

<div class="post-metadata">

**Author:** ![mshevchuk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@mshevchuk](https://org-roam.discourse.group/u/mshevchuk)\
**Post date:** [January 24, 2022, 1:10pm UTC](https://org-roam.discourse.group/t/nested-capture-keys/2399/2 "2022-01-24T13:10:39Z")

</div>

Yes, it’s possible. Org-roam-capture-templates are just an extension to Org-capture-templates.

---

<div class="post-metadata">

**Author:** ![tbd](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@tbd](https://org-roam.discourse.group/u/tbd)\
**Post date:** [January 25, 2022, 3:27am UTC](https://org-roam.discourse.group/t/nested-capture-keys/2399/3 "2022-01-25T03:27:26Z")

</div>

Thank you. Is this shown in the manual on how to do this? Can you please point an example?

---

<div class="post-metadata">

**Author:** ![mshevchuk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@mshevchuk](https://org-roam.discourse.group/u/mshevchuk)\
**Post date:** [January 25, 2022, 5:11pm UTC](https://org-roam.discourse.group/t/nested-capture-keys/2399/4 "2022-01-25T17:11:49Z")

</div>

> [@tbd](#):
>
> Is this shown in the manual on how to do this?

Yes, evaluate this expression: `(info "(Org)Template elements")`. Also consult the docstring `C-h v org-capture-templates`.

> [@tbd](#):
>
> Can you please point an example?

```elisp
(setq org-roam-capture-templates
  '(("d" "default" ...)
    ("p" "Programming")
    ("pp" "python" ...)
    ("pc" "c" ...)
    ("pr" "r" ...)
      ...etc...))

```

You define the group as a list of two elements `(KEY NAME)`, then define actual templates as usual using a two-letter sequence for the key.

---

<div class="post-metadata">

**Author:** ![tbd](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@tbd](https://org-roam.discourse.group/u/tbd)\
**Post date:** [January 26, 2022, 3:15am UTC](https://org-roam.discourse.group/t/nested-capture-keys/2399/5 "2022-01-26T03:15:22Z")

</div>

Thank you. I set it similar to my orgmode capture template and was getting all sorts of error which prompted me to post the question. I will read the docstring and try again. Thanks for your time.

---

<div class="post-metadata">

**Author:** ![nickanderson](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nickanderson/32/753_2.png) [@nickanderson](https://org-roam.discourse.group/u/nickanderson)\
**Post date:** [January 31, 2022, 7:07pm UTC](https://org-roam.discourse.group/t/nested-capture-keys/2399/6 "2022-01-31T19:07:14Z")

</div>

Here is another example showing daily templates. You can see that I have some key bindings for various customer meetings. I have the customers organized alphabetically so when I have two customers that share the first few characters I create a deeper nest.

See `wmcdir` (work, meeting customer, d (first letter of customer name), i (second letter of customer name), r (capture tempalte for customer starting with dir). The trick is that you have to have an entry for each branch point. So I have `wm` for work meetings and `wmc` for Customer (under work meetings) and `wmcd` for work meetings for customers that start with the letter d.

```
(setq org-roam-dailies-capture-templates
      `(
        ("j" "Journal" entry
         "* %?"
         :if-new (file+head ,(expand-file-name "journal/%<%Y-%m-%d>.org" org-roam-dailies-directory)
                            "#+title: %<%A, %B %d %Y>")
         :clock-in nil
         :clock-resume nil
         )

        ("w" "Work" )

        ("wl" "Log" entry
         "* %?"
         :if-new (file+head ,(expand-file-name "work/%<%Y-%m-%d>.org" org-roam-dailies-directory)
                            "#+title: Work log for %<%Y-%m-%d>")
         :clock-in t
         :clock-resume t
         )

        ("we" "Email" entry
         "* Respond to %:fromname Re: %:subject\n%a\n#+begin_quote\n %i\n#+end_quote\n\n%?"
         :if-new (file+head ,(expand-file-name "work/%<%Y-%m-%d>.org" org-roam-dailies-directory)
                            "#+title: Work log for %<%Y-%m-%d>")
         :clock-in t
         :clock-resume t
         )

        ("wm" "Work Meetings")
        ("wmc" "Customer")
        ("wmca" "A" plain
         (file "~/org/roam/daily/my-company/meetings/customer/TEMPLATE")
         :if-new (file+head ,(expand-file-name "my-company/meetings/customer/A/%<%Y-%m-%d>.org" org-roam-dailies-directory)
                            "#+PROPERTY: CUSTOMER A\n#+PROPERTY: MAIL_TO My Team <my@team.tld>\n#+PROPERTY: MAIL_SUBJECT Meeting notes: Customer Sync w/ A\n#+PROPERTY: MAIL_FROM Nick Anderson <nick@cmdln.org>\n#+title: Customer Sync with A %<%A, %B %d, %Y>\n#+filetags: :CFEngine:customer_meeting:customer:\n")
         :unnarrowed t
         :append t
         )

        ("wmcd" "D")
        ("wmcdi" "i")
        ("wmcdir" "Dirasto" plain
         (file "~/org/roam/daily/my-company/meetings/customer/TEMPLATE")
         :if-new (file+head ,(expand-file-name "my-company/meetings/customer/Dirasto/%<%Y-%m-%d>.org" org-roam-dailies-directory)
                            "#+PROPERTY: CUSTOMER Dirasto\n#+PROPERTY:\nMAIL_TO: My Team <my@team.tld>\n#+PROPERTY: MAIL_SUBJECT Meeting notes: Customer Sync w/ Dirasto\n#+PROPERTY: MAIL_FROM Nick Anderson <nick@cmdln.org>\n#+title: Customer Sync with Dirasto %<%A, %B %d, %Y>\n#+filetags: :customer_meeting:customer:\n")
         :unnarrowed t
         :append t
         )

        ("wmcdis" "District Five" plain
         (file "~/org/roam/daily/my-company/meetings/customer/TEMPLATE" )
         :if-new (file+head ,(expand-file-name "my-company/meetings/customer/District_Five/%<%Y-%m-%d>.org" org-roam-dailies-directory)
                            "#+PROPERTY: CUSTOMER District Five\n#+PROPERTY:\n MAIL_TO: Team <my@team.tld>\n#+PROPERTY: MAIL_SUBJECT Meeting notes: Customer Sync w/ District Five\n#+PROPERTY: MAIL_FROM Nick Anderson <nick@cmdln.org>\n#+title: Customer Sync with District Five %<%A, %B %d, %Y>\n#+filetags: ::customer_meeting:customer:\n")
         :unnarrowed t
         :append t
         ))
```
