Hi Jan!
On Fri, 09 Jul 2004 23:57:42 -0700, Jan Rychter jan@rychter.com wrote:
First of all, I'd like to thank you for the excellent libraries that you make available. I particularly appreciate how carefully finished and documented they are.
Thanks, you're welcome.
I would like to ask you a question regarding HTML-template -- somehow I cannot get to work the way I would like to. I am puzzled as to what I'm doing wrong: I have read and reread the documentation, and tried a number of things.
The problem I have is that my templates print on the standard output (in the REPL) instead of being captured into strings. The absolutely narrowed-down example is:
(with-output-to-string (*standard-output*) (with-input-from-string (s "test <!-- TMPL_VAR a --> one") (html-template:fill-and-print-template s '(:a "1"))))
This prints "test 1 one" in my REPL and returns an empty string.
This happens because FILL-AND-PRINT-TEMPLATE rebinds *STANDARD-OUTPUT* to the value of *DEFAULT-TEMPLATE-OUTPUT* which is *STANDARD-OUTPUT* (the original one!) by default.
I admit that this is an unfortunate design decision which happened mainly because I was too lazy to type. I might chance this in a future release.
In other words: All statements like
(write-string string)
in CREATE-SIMPLE-PRINTER in 'template.lisp' should rather be
(write-string string *default-template-output*)
instead. That way I wouldn't need the
(let ((*standard-output* stream))
rebinding in 'api.lisp'.
Adding a :stream *standard-output* argument to fill-and-print-template helps in this case. However, it doesn't help at all if I call this code from TBNL. In that case, everything still ends up in the standard output of my REPL, instead of on the web page.
I'm sorry for bothering you with such a trivial problem. Perhaps you could add a simple usage example together with TBNL to the documentation of one of the packages?
All of these should work:
(with-output-to-string (*default-template-output*) (with-input-from-string (s "test <!-- TMPL_VAR a --> one") (html-template:fill-and-print-template s '(:a "1"))))
(with-output-to-string (out) (with-input-from-string (s "test <!-- TMPL_VAR a --> one") (html-template:fill-and-print-template s '(:a "1") :stream out)))
(with-output-to-string (out) (let ((*default-template-output* out)) (with-input-from-string (s "test <!-- TMPL_VAR a --> one") (html-template:fill-and-print-template s '(:a "1")))))
This is also documented here:
http://weitz.de/html-template/#default-template-output
Let me know if this works for you or if you still have problems.
Cheers, Edi.
PS: I'm sending a copy to the mailing list. Please use the list for bug reports and questions. Thanks.
html-template-devel@common-lisp.net