# Help with template and file+olp

**URL:** <https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264>\
**Category:** Troubleshooting\
**Created:** [December 9, 2021, 4:23am UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264 "2021-12-09T04:23:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathan](https://org-roam.discourse.group/u/jonathan)\
**Post date:** [December 9, 2021, 4:23am UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/1 "2021-12-09T04:23:43Z")

</div>

I’m trying to write a template such that I can capture a movie title and put it in my existing org-roam file `movies.org`, under the heading “Watched.” Here’s that template:

```auto
  (setq org-roam-capture-templates
        '(... 
          ("m" "movie" plain "%?" :target
           (file+olp "movies.org" ("Watched")
                     "*** \n :PROPERTIES:\n :RATING:\n:END:\n%t\n")
           )))

```

But whenever I run org-roam-capture, and select “m,” it says “wrong type argument, integer-or-marker-p, nil.”

What am I doing wrong here? I’ve tried it every way I can think to try it, so far.

---

<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:** [December 9, 2021, 9:00pm UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/2 "2021-12-09T21:00:50Z")

</div>

> [@jonathan](#):
>
> What am I doing wrong here?

You are using an invalid list. From the docstring for `org-roam-capture-templates`:

```plaintext
   (file+olp "path/to/file" ("h1" "h2"))
       The file will be created, prescribed an ID. If the file doesn't contain
       the outline path (h1, h2), it will be automatically created. The point
       will be adjusted to the last element in the OLP.

```

It should be

```elisp
...  
(file+olp "movies.org" ("Watched"))
...

```

---

<div class="post-metadata">

**Author:** ![jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathan](https://org-roam.discourse.group/u/jonathan)\
**Post date:** [December 10, 2021, 4:52pm UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/3 "2021-12-10T16:52:10Z")

</div>

Now it runs without error, with this:

```auto
  (setq org-roam-capture-templates
        '(("d" "default" plain "%?" :target
           (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
           :unnarrowed t)
          ("m" "movie" plain "*** ${title}\n :PROPERTIES:\n :RATING:\n:END:\n%t\n"
           :target (file+olp "movies.org" ("Watched")
           ))))

```

But I have an even bigger problem now: it wants to rewrite my whole existing [movies.org](http://movies.org) file, instead of just adding something to it. It creates a new buffer with the same name but different contents.

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [December 10, 2021, 9:58pm UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/4 "2021-12-10T21:58:21Z")

</div>

Copy and pasted your setq (left buffer below); seems to work on my end (right buffer):

 ![Screenshot from 2021-12-10 22-56-52](https://global.discourse-cdn.com/free1/uploads/orgroam/original/2X/e/e3caca09f033599ffb51a4dd8c32ea652edca7d7.png)

---

<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:** [December 11, 2021, 9:18am UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/5 "2021-12-11T09:18:41Z")

</div>

> [@jonathan](#):
>
> It creates a new buffer with the same name but different contents.

Could it be you are talking about the transient `*Org-capture-...*` buffer? You’d need to press `C-c C-c` to finalize the capture process.

---

<div class="post-metadata">

**Author:** ![jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathan](https://org-roam.discourse.group/u/jonathan)\
**Post date:** [December 11, 2021, 6:46pm UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/6 "2021-12-11T18:46:14Z")

</div>

Ah so I figured out what was wrong with the duplicate files—it turns out I had two org files, one called `movies.org` and one called `movies.org ` with a space at the end. And that was throwing everything off.

So now it works as in @nobiot’s screenshot above.

But it’d be really nice to have the headings get IDs, so they’re indexed by org-roam as nodes. Is that possible?

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [December 12, 2021, 8:35pm UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/7 "2021-12-12T20:35:33Z")

</div>

You should be able to call a function with using `%` as a prefix like this: `%(org-id-get-create)`. I think you can put it in in your template (somewhere after your “\*\*\*”) — can’t test it now but you can read it in the docstring of `org-roam-capture-templates` (`C-h v`).

---

<div class="post-metadata">

**Author:** ![jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathan](https://org-roam.discourse.group/u/jonathan)\
**Post date:** [December 17, 2021, 2:58am UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/8 "2021-12-17T02:58:58Z")

</div>

That doesn’t seem to work. I just get the literal `%(org-id-get-create)` appear in my capture buffer. With this:

```auto
  (setq org-roam-capture-templates
        '(("d" "default" plain "%?" :target
           (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
           :unnarrowed t)
          ("m" "movie" plain "*** ${title}\n :PROPERTIES:\n :ID: %(org-id-get-create)\n :RATING:\n :END:\n%t\n"
           :target (file+olp "movies.org" ("Watched")
           ))))

```

I get this:

```auto
*** Test
 :PROPERTIES:
 :ID: %(org-id-get-create)
 :RATING:
 :END:
<2021-12-16 ĵaŭ>

```

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [December 17, 2021, 8:35am UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/9 "2021-12-17T08:35:42Z")

</div>

It seems like `org-id-get-create` expects the buffer to be visiting a file

> (error ‘org-id-get’ expects a file-visiting buffer)

This below seems to work for me (lightly tested). I guess you’d need to adjust the function according to the ID you use (e.g. I use a certain date format instead of uuid).

```auto
  (setq org-roam-capture-templates
        '(("d" "default" plain "%?" :target
           (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
           :unnarrowed t)
          ("m" "movie" plain "*** ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n :RATING:\n :END:\n%t\n"
           :target (file+olp "movies.org" ("Watched")
           ))))

```

 ![Screenshot from 2021-12-17 09-42-22](https://global.discourse-cdn.com/free1/uploads/orgroam/original/2X/8/85f691d2ac0380286be9249d0b616fa0b26d630a.png)

---

<div class="post-metadata">

**Author:** ![jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathan](https://org-roam.discourse.group/u/jonathan)\
**Post date:** [December 17, 2021, 1:52pm UTC](https://org-roam.discourse.group/t/help-with-template-and-file-olp/2264/10 "2021-12-17T13:52:02Z")

</div>

Great! That works. Thanks!
