2

I'm trying to generate the following html code using cl-who:

<html>
<body>
<div id="cnt_1"></div>
<div id="cnt_2"></div>
<div id="cnt_3"></div>
</body>
</html>

And here's the code that I thought would work:

(with-html-output-to-string (*standard-output* nil)
 (:html
  (:body
   (do ((cnt 1 (+ cnt 1)))
       ((> cnt 3))
     (htm (:div :id (format t "cnt_~A" cnt)))))))

But instead I get the following output:

<html><body><divcnt_1></div><divcnt_2></div><divcnt_3></div></body></html>

Seems like :id does not work with function calls. Does it mean that I can't use format in cl-who? What should I use instead?

1 Answer 1

5

That's because you don't want to write directly in the stream.

CL-USER> (with-html-output-to-string (s) (:div :id "test"))
"<div id='test'></div>"

CL-USER> (with-html-output-to-string (s)
           (:html
            (:body
             (do ((cnt 1 (+ cnt 1)))
                 ((> cnt 3))
               (htm (:div :id (format nil "cnt_~A" cnt)))))))

"<html><body><div id='cnt_1'></div><div id='cnt_2'></div><div id='cnt_3'></div></body></html>"

By the way, if you want to write directly in the stream use CL-WHO:FMT.

2
  • FMT works in the content section in the syntax, not the attribute value section.
    – Xach
    Jul 3, 2012 at 16:25
  • @Xach: By work I suppose that you mean it does what you expect, because it works just like the op's FORMAT (write into the current stream).
    – Daimrod
    Jul 3, 2012 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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