1

A complete org-capture template consists of six elements: keys, description, type, target, template, and properties. The manual explains how to use %-escapes to allow dynamic insertion of content into the template element, but is there any way to do the same thing into the target element?

For example, I have a set of templates I call annoyances in which I capture things that frustrate me about various pieces of software (I dunno why -- maybe so I can gather them together and one day sue someone!) They capture to a single file, but under headings grouping either a vendor or particular piece of software. Something like this fragment:

("a"  "Annoyance")
("aa" "Apple"
 entry (file+headline "~/org/annoyances.org"  "Apple") 
"* ANNOYANCE %^{Title}\n%?"
 :prepend t :empty-lines: 1)
("ae" "Evernote"
 entry (file+headline "~/org/annoyances.org"  "Evernote") 
 "* ANNOYANCE %^{Title}\n%?"
 :prepend t :empty-lines: 1)
("ag" "Google"
 entry (file+headline "~/org/annoyances.org"  "Google") 
 "* ANNOYANCE %^{Title}\n%?"
 :prepend t :empty-lines: 1)

... and so on

But other than the names of the culprits, those templates are all identical, and my actual templates are a bit longer than those I've shown, and the list of people-or-code-I-love-to-hate is growing, so to save a lot of duplication what I'd rather have is a single template that Just Figures It Out from the content I provide during capture. Something like this (obviously broken) fragment:

("a"  "Annoyance"
 entry (file+headline "~/org/annoyances.org"  %^{Culprit}) 
"* ANNOYANCE %^{Title}\n%?"
 :prepend t :empty-lines: 1)

An alternative method would be to use tags since those live in the template element and so can make use of the %-escapes, and then I can use sparse trees if I want to home in on a particular culprit. But is there a way to have the target element dynamically created in the process of entering a capture, e.g. by somehow getting a %-escape value into the target?

1

Just write a function to add the template: and call it for each annoyance:

(defun add-annoyance (key product)
  (add-to-list 'org-capture-templates
               `(,(concat "a" key) ,product
                 entry (file+headline "~/org/annoyances.org"  "Google") 
                 "* ANNOYANCE %^{Title}\n%?"
                 :prepend t :empty-lines: 1)))

(add-annoyance "g" "Google")

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.