From edi at agharta.de Fri Jul 9 23:45:15 2004 From: edi at agharta.de (Edi Weitz) Date: Sat, 10 Jul 2004 01:45:15 +0200 Subject: [html-template-devel] Re: question regarding HTML-TEMPLATE In-Reply-To: (Jan Rychter's message of "Fri, 09 Jul 2004 23:57:42 -0700") References: Message-ID: <87smc0iw38.fsf@bird.agharta.de> Hi Jan! On Fri, 09 Jul 2004 23:57:42 -0700, Jan Rychter 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 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 one") (html-template:fill-and-print-template s '(:a "1")))) (with-output-to-string (out) (with-input-from-string (s "test 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 one") (html-template:fill-and-print-template s '(:a "1"))))) This is also documented here: 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. From edi at agharta.de Sat Jul 10 09:17:45 2004 From: edi at agharta.de (Edi Weitz) Date: Sat, 10 Jul 2004 11:17:45 +0200 Subject: [html-template-devel] [Jan Rychter] Re: question regarding HTML-TEMPLATE Message-ID: <87briomdae.fsf@bird.agharta.de> Here's Jan's answer (he replied to the list but forgot to subscribe) which explains why his code worked in the REPL but not in TBNL. Edi. -------------- next part -------------- An embedded message was scrubbed... From: Jan Rychter Subject: Re: question regarding HTML-TEMPLATE Date: Sat, 10 Jul 2004 05:32:40 -0700 Size: 2998 URL: