noweb expantion is a very nice tool but it generally allows one to refer to other src-code blocks:
#+NAME: hellomessage
#+BEGIN_SRC emacs-lisp
"hello"
#+END_SRC
#+BEGIN_SRC emacs-lisp :noweb yes
(message <<hellomessage>>)
#+END_SRC
works perfectly. But it is reasonable to want to do template expansion with properties. I would like something like this to work:
#+PROPERTY: hellomessage hello
#+BEGIN_SRC emacs-lisp :noweb yes
(message "<<hellomessage>>")
#+END_SRC
or
* Example
:PROPERTIES:
:hellomessage: hello
:END:
#+BEGIN_SRC emacs-lisp :noweb yes
(message "<<hellomessage>>")
#+END_SRC
but it doesn't since noweb seems only to expand named source blocks. Is there any way to do this?
I have thought of using header arguments with the var keyword but that seems somewhat artificial since the property then is "specific" to src blocks. I would like to avoid this since I would also want to use the property in the normal org-mode way.
Similarly to what Ixemad suggested I tried doing this
* Example
:PROPERTIES:
:hellomessage: hello
:END:
#+NAME: get_property
#+BEGIN_SRC elisp :var prop=""
(org-entry-get nil prop t)
#+END_SRC
#+RESULTS: get_property
#+BEGIN_SRC emacs-lisp :noweb yes
(message "<<get_property("hellomessage")>>")
#+END_SRC
#+RESULTS:
: hello1
but the problem is that the org-entry-get
gets evaluated where the get_property
code block is defined, not where it is called as seen by the following example
* Example1
:PROPERTIES:
:hellomessage: hello1
:END:
#+NAME: get_property
#+BEGIN_SRC elisp :var prop=""
(org-entry-get nil prop t)
#+END_SRC
#+RESULTS: get_property
#+BEGIN_SRC emacs-lisp :noweb yes
(message "<<get_property("hellomessage")>>")
#+END_SRC
#+RESULTS:
: hello1
* Example2
:PROPERTIES:
:hellomessage: hello2
:END:
#+BEGIN_SRC emacs-lisp :noweb yes
(message "<<get_property("hellomessage")>>")
#+END_SRC
#+RESULTS:
: hello1
The second result should have been hello2
.