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?
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.