# Read capture template from file

**URL:** <https://org-roam.discourse.group/t/read-capture-template-from-file/1869>\
**Category:** Requests\
**Created:** [July 31, 2021, 4:56pm UTC](https://org-roam.discourse.group/t/read-capture-template-from-file/1869 "2021-07-31T16:56:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sthysel](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/sthysel/32/503_2.png) [@sthysel](https://org-roam.discourse.group/u/sthysel)\
**Post date:** [July 31, 2021, 4:56pm UTC](https://org-roam.discourse.group/t/read-capture-template-from-file/1869/1 "2021-07-31T16:56:09Z")

</div>

Hello,  
I’m trying to do something that I expected to be pretty trivial but no…

I want to read the roam template from a file like I do for org below.

```auto
  (setq org-roam-capture-templates
        (quote
         (
          ("d" "default" plain "%?"
           :if-new (file+head "${slug}.org" (file "~/org/templates/roam-default.template"))
           :immediate-finish t
           :unnarrowed t)
          )
         )
        )

  (setq org-capture-templates
        (quote
         (("p" "Private templates")
          ("pt" "TODO entry" entry
           (file+headline "~/org/private.org" "Capture")
           (file "~/org/templates/todo.txt"))))
  )

```

The code documentation is no help to me either.

```auto
template The template for creating the capture item.
             If it is an empty string or nil, a default template based on
             the entry type will be used (see the \"type\" section above).
             Instead of a string, this may also be one of:

                 (file \"/path/to/template-file\")
                 (function function-returning-the-template)

             in order to get a template from a file, or dynamically
             from a function.

The template contains a compulsory :if-new property. This determines the
location of the new node. The :if-new property contains a list, supporting
the following options:

   (file \"path/to/file\")
       The file will be created, and prescribed an ID.

```

---

<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:** [August 1, 2021, 12:27am UTC](https://org-roam.discourse.group/t/read-capture-template-from-file/1869/2 "2021-08-01T00:27:13Z")

</div>

You just need to fix the structure of your list.

First let’s check the structure of `org-capture-templates`:

```auto
(setq org-capture-templates
        '(("pt" ;; <= KEYS
           "Private templates" ;; <= DESCRIPTION
            entry ;; <= TYPE
           (file+headline "org-private.org" "Capture") ;; <= TARGET
           (file "~/org/templates/todo.txt") ;; <= TEMPLATE
           ... ;; &rest plist
           ...))         

```

Now let’s inspect `org-roam-capture-templates`:

```auto
(setq org-roam-capture-templates
        '(("pt" ;; <= KEYS
           "Private templates" ;; <= DESCRIPTION
            entry ;; <= TYPE
           ;; <= TARGET is not on the list, sort of hidden;
           ;; in fact, it's in the plist
           (file "~/org/templates/todo.txt") ;; <= TEMPLATE
           :if-new (file+headline "org-private.org" "Capture") ;; &rest plist
           ...))

```

So all what you need is to replace `"%?" with `(file “~/org/templates/todo.txt”)`.

---

<div class="post-metadata">

**Author:** ![sthysel](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/sthysel/32/503_2.png) [@sthysel](https://org-roam.discourse.group/u/sthysel)\
**Post date:** [August 1, 2021, 6:08am UTC](https://org-roam.discourse.group/t/read-capture-template-from-file/1869/3 "2021-08-01T06:08:40Z")

</div>

Thanks mate - that helped a lot.

Below works for me in spacemacs.

```auto
  (setq org-roam-capture-templates
        '(("d" ;; key
           "default" ;; description
           plain ;; type
           (file "~/org/templates/roam-default.template") ;; template
           :if-new (file "${slug}.org") ;; target
           :immediate-finish t
           :unnarrowed t)
          )
         )

  (setq org-capture-templates
        '(("p" "Private templates") ;; main menu
          ("pt" ;; keys
           "TODO entry"
           entry
           (file+headline "~/org/private.org" "Capture")
           (file "~/org/templates/todo.txt")
           )
          )

```

---

<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:** [August 1, 2021, 9:40am UTC](https://org-roam.discourse.group/t/read-capture-template-from-file/1869/4 "2021-08-01T09:40:22Z")

</div>

You are welcome.
