[cl-who-devel] Interpolate lisp code inside the tag body

Hello i just starting working with cl-who and i have one very basic question: How does one properly embed and evaluate lisp code inside the tag body? Let's say i have a function "fn" which returns a string and i want to embed its value in a tag, like: (: p (fn)) -> that does not work. Thanks for help Matus

Quoth Matus Kmit <simply.nitaai@gmail.com>:
How does one properly embed and evaluate lisp code inside the tag body?
You can 'embed' the *value* of an attribute, but not attributes themselves. In practice this is not a serious limitation.
(:p (fn)) does not work.
No, but this does: (flet ((fn () "value")) (with-html-output-to-string (s) (:p :attribute (fn)))) => "<p attribute='value'></p>" Note, that to do something similar in the text node of an element, you should use one of the exported symbols; esc, fmt or str. http://weitz.de/cl-who/#esc For example: (flet ((fn () "Attributes and their values")) (with-html-output-to-string (s) (:h1 (str (fn))))) => "<h1>Attributes and their values</h1>" Hope this helps, Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap

Yes, this helps. i think it also answers my second post -> one should use "with-html-output-to-string"... Right? Matus On Thu, Jul 28, 2011 at 10:06 AM, Sebastian Tennant <sebyte@smolny.plus.com> wrote:
Quoth Matus Kmit <simply.nitaai@gmail.com>:
How does one properly embed and evaluate lisp code inside the tag body?
You can 'embed' the *value* of an attribute, but not attributes themselves.
In practice this is not a serious limitation.
(:p (fn)) does not work.
No, but this does:
(flet ((fn () "value")) (with-html-output-to-string (s) (:p :attribute (fn)))) => "<p attribute='value'></p>"
Note, that to do something similar in the text node of an element, you should use one of the exported symbols; esc, fmt or str.
For example:
(flet ((fn () "Attributes and their values")) (with-html-output-to-string (s) (:h1 (str (fn))))) => "<h1>Attributes and their values</h1>"
Hope this helps,
Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap
_______________________________________________ cl-who-devel site list cl-who-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cl-who-devel

Let me specify further my question. if i do: (with-html-output (*standard-output*) (:body (:p (str (fn)))) then the generated html code is correct but the return string is not complete: <body><p>text</p></body> "</p></body>" Thus if i publish this function the web page is blank. If i do the same with with-html-output-to-string however, i get the correct string and the published webpage is displayed correctly: "<body><p>text</p></body>" (the code is only a snippet of the web page) Does that mean that one should use only with-html-output-to-string for publishing or is there something wrong with the way i am embedding the lisp code? Thanks Matus On Thu, Jul 28, 2011 at 9:12 AM, Matus Kmit <simply.nitaai@gmail.com> wrote:
Hello
i just starting working with cl-who and i have one very basic question:
How does one properly embed and evaluate lisp code inside the tag body?
Let's say i have a function "fn" which returns a string and i want to embed its value in a tag, like:
(: p (fn)) -> that does not work.
Thanks for help Matus

Quoth Matus Kmit <simply.nitaai@gmail.com>:
Does that mean that one should use only with-html-output-to-string for publishing
Yes. Let's say your dispatch handler (a hunchentoot term) calls function home-page, then home-page should look like this: (defun home-page () (with-html-output-to-string (*http-stream*) (:p ...) ...)) where *http-stream* is defined as a special variable, like so: (defun *http-stream* nil) Now, let's assume home-page includes a call to function navbar. navbar doesn't need to use w-h-o-t-s. This will suffice: (defun (navbar () (with-html-output (*http-stream*) (:div :id "navbar" ...) ...)) In short, only the 'top-level' function called by your dispatch handler needs to use w-h-o-t-s. Hope this helps. Sebastian

Excellent. THANKS. Matus On Mon, Aug 1, 2011 at 8:23 PM, Sebastian Tennant <sebyte@smolny.plus.com> wrote:
Quoth Matus Kmit <simply.nitaai@gmail.com>:
Does that mean that one should use only with-html-output-to-string for publishing
Yes. Let's say your dispatch handler (a hunchentoot term) calls function home-page, then home-page should look like this:
(defun home-page () (with-html-output-to-string (*http-stream*) (:p ...) ...))
where *http-stream* is defined as a special variable, like so:
(defun *http-stream* nil)
Now, let's assume home-page includes a call to function navbar.
navbar doesn't need to use w-h-o-t-s. This will suffice:
(defun (navbar () (with-html-output (*http-stream*) (:div :id "navbar" ...) ...))
In short, only the 'top-level' function called by your dispatch handler needs to use w-h-o-t-s.
Hope this helps.
Sebastian
_______________________________________________ cl-who-devel site list cl-who-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cl-who-devel

i wondered, but thought it might be another of lisp's elastic features, known only to the advanced lisp hackers :-) Matus On Thu, Aug 4, 2011 at 1:46 PM, Sebastian Tennant <sebyte@smolny.plus.com> wrote:
Quoth Matus Kmit <simply.nitaai@gmail.com>:
Excellent. THANKS.
I hope you spotted my deliberate mistake.
Special variables are declared with defvar (not defun).
Sebastian
_______________________________________________ cl-who-devel site list cl-who-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cl-who-devel
participants (2)
-
Matus Kmit
-
Sebastian Tennant