# SOLVED - Trouble with Initial Content in Capture Template

**URL:** <https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206>\
**Category:** Troubleshooting\
**Created:** [January 23, 2021, 11:12pm UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206 "2021-01-23T23:12:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jprussell](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jprussell/32/360_2.png) [@jprussell](https://org-roam.discourse.group/u/jprussell)\
**Post date:** [January 23, 2021, 11:12pm UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/1 "2021-01-23T23:12:32Z")

</div>

Hi all, I have what I hope is a relatively simple troubleshooting question (cross-posted on the Slack channel as well) about the use of the “Initial Content (%i)” org capture expansion in org-roam-capture.

**Desired Behavior**  
I would like to highlight text, call org-roam-find-file, select the desired template (in the case of below “Test”), and then get a capture buffer to edit that is pre-populated with the selected text. I’ve simplified the below configuration from the full template I’d like to use to minimize factors that might be messing it up.

**Currently Observed Behavior**  
I select the text, call org-roam-find-file, select the “Test” template, and then I get a capture buffer that shows the text that was highlighted the first time I selected text and called this template after a restart of emacs.

**Already-Attempted Troubleshooting**  
So, the first time I try this after restarting emacs, it works as expected, but every time after it re-uses the text that was selected the first time I used the template.

First, I simplified the template as much as possible to make sure no other formatting or expansions were interfering. Then I replaced the “initial content (%i)” expansion with the “head of the kill-ring (%c)” expansion - this works as expected (capture template opens with the last text killed or copied). I’ve tried to see whether it matters if I abort or accept the capture template (it seems not to), whether it matters which buffer I call it from (it seems not to), and whether using another template in between uses of this template makes a difference (it seems not to).

**Current Configuration**

```auto
(setq org-roam-capture-templates
  '(("t" "Test" plain (function org-roam-capture--get-point)
     "%i%?"
     :file-name "Roam_Notes/%<%Y%m%d%H%M%S>-${slug}"
     :head "#+title: ${title}\n#+roam_alias: \n#+roam_tags: \n\n"
     :unnarrowed t)))

```

**Question**  
So, does anyone have an idea 1) why the %i is getting stuck on the text selected when I first call the capture template, and more importantly 2) any idea how to change it to behave as expected?

Thanks very much to anyone with thoughts!

---

<div class="post-metadata">

**Author:** ![rakoenig](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/rakoenig/32/579_2.png) [@rakoenig](https://org-roam.discourse.group/u/rakoenig)\
**Post date:** [January 24, 2021, 10:58am UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/2 "2021-01-24T10:58:18Z")

</div>

There was [a discussion on Slack](https://orgroam.slack.com/archives/CTS32BB6J/p1611295639004700) about this 2 days ago. Yes, I also noticed that %i in stopped working with org-ref-protocol. In my case that can be fixed by using ${body} instead of %i because the org-ref-javascript provides the body variable.

I just tried with a normal org-capture template, it seems that “%i” expansion only works when you hightlight a region inside Emacs and call the caputure template from **this** emacs window. Highlighting text in other Emacs windows or even in a web browser didn’t work in “normal org caputre” either.

I also can’t see a commit in org-roam that should be blamed for this, maybe a recent emacs update did the damage.

---

<div class="post-metadata">

**Author:** ![jprussell](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jprussell/32/360_2.png) [@jprussell](https://org-roam.discourse.group/u/jprussell)\
**Post date:** [January 24, 2021, 4:38pm UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/3 "2021-01-24T16:38:47Z")

</div>

@rakoenig Interesting, thank you for linking the previous discussion! I looked around here for previous topics, but did not search the slack as thoroughly.

I don’t know if this is related, but I was having another org-related issue yesterday before I started working on the capture template. For some reason, `:VISIBILITY:` properties were not working correctly, and the only fix I could find for it was to revert to the built-in org version (9.3) instead of using the latest via straight.el (9.4.4). I just tried going back to 9.4.4 and the problem persists.

Unfortunately, my elisp is very rudimentary, so I haven’t been able to get very far looking at the org or org-roam source.

---

<div class="post-metadata">

**Author:** ![jprussell](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jprussell/32/360_2.png) [@jprussell](https://org-roam.discourse.group/u/jprussell)\
**Post date:** [January 24, 2021, 4:50pm UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/4 "2021-01-24T16:50:18Z")

</div>

Oh, also, I should have clarified based on what you said: the above-described behavior has been entirely within the same emacs frame - I’ve been highlighting text in a buffer, pressing `C-c n f` (my keybinding for `org-roam-find-file`), and getting the results I talked about.

---

<div class="post-metadata">

**Author:** ![jprussell](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jprussell/32/360_2.png) [@jprussell](https://org-roam.discourse.group/u/jprussell)\
**Post date:** [January 24, 2021, 5:23pm UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/5 "2021-01-24T17:23:21Z")

</div>

At the suggestion of mshevchuk over on the Slack, I updated my installation of org-roam via straight.el and that seems to have solved the problem! Should have been the first thing I tried. Thanks for your help @rakoenig.

---

<div class="post-metadata">

**Author:** ![Adela](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@Adela](https://org-roam.discourse.group/u/Adela)\
**Post date:** [February 20, 2021, 7:37pm UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/6 "2021-02-20T19:37:52Z")

</div>

Is %i working again or shall we use {body}? Thanks!

---

<div class="post-metadata">

**Author:** ![jprussell](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jprussell/32/360_2.png) [@jprussell](https://org-roam.discourse.group/u/jprussell)\
**Post date:** [February 22, 2021, 5:08am UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/7 "2021-02-22T05:08:54Z")

</div>

Hi Adela,

I am not sure what the most preferred answer, but my current template uses `%i` and has been working fine after updating org-roam.

Please see below for the template I use that includes `%i`:

```auto
          ("s" "Slip" plain #'org-roam-capture--get-point
           "** Body
   :PROPERTIES:
   :VISIBILITY: all
   :END:
   %i%?

** Where From
   :PROPERTIES:
   :VISIBILITY: folded
   :END:

** Links
   :PROPERTIES:
   :VISIBILITY: folded
   :END:

** Tags
   :PROPERTIES:
   :VISIBILITY: folded
   :END:

"
           :file-name "%(jpr-org-roam-slip-name)-${slug}"; the way you put functions into this keyword is to put a '%' before the opening parenthesis, enclosed within a string
           :head "#+title: ${title}\n#+roam_alias: \n#+roam_tags: \n\n#+PROPERTY: Slip_ID NNNN\n#+PROPERTY: Firstness 50\n#+PROPERTY: DATE %<%Y-%m-%d %H%M>\n\n"
           :unnarrowed t)

```

If you’re interested in what I was doing with `(jpr-org-roam-slip-name)` in the file name, check out this [post](https://org-roam.discourse.group/t/how-to-customize-file-name-and-path-at-time-of-capture/1213/1) explaining the problem I had and how I solved it.

---

<div class="post-metadata">

**Author:** ![Adela](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@Adela](https://org-roam.discourse.group/u/Adela)\
**Post date:** [February 22, 2021, 9:28am UTC](https://org-roam.discourse.group/t/solved-trouble-with-initial-content-in-capture-template/1206/8 "2021-02-22T09:28:40Z")

</div>

Thanks for your kind answer. %i does not work for me.

My current working template needs to contain “body” in `org-roam-capture-ref-templates`:

```
 ("i" "incremental" plain
         #'org-roam-capture--get-point
         "${body}\n%?" ;; this reads from
        ; "%i%?"
         :empty-lines-before 1
         :file-name "web/${slug}"
         :head "#+title: ${title}\n#+roam_key ${ref}\n#+CREATED: %U\n#+LAST_MODIFIED: %U\n\n"
         :unnarrowed t)))

```

And the bookmarklet, which is the default, is the one below, where you see that “body” is specified.

`javascript:location.href = 'org-protocol://roam-ref?template=i&ref=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title) + '&body=' + encodeURIComponent(window.getSelection())`
