[html-template-devel] problem with UTF characters in template

Dimitre Liotev dl at znain.net
Fri May 18 18:55:33 UTC 2007


Edi Weitz <edi at agharta.de> writes:

> On Fri, 18 May 2007 11:24:15 -0400, Dimitre Liotev <dl at znain.net> wrote:
>
>> I am using the "Simple example" from your page
>> http://weitz.de/html-template/, specifying :external-format "UTF-8"
>> in the call to create-template-printer:
>
> Is the string "UTF-8" a valid external format specifier on AllegroCL?

I thought so, but it seems that the format must be specified as a keyword:

CL-USER> (describe (find-if (lambda (x)
                              (member :UTF-8 (excl:ef-nicknames x)))
                            (EXCL:ALL-EXTERNAL-FORMATS)))

#<EXTERNAL-FORMAT :UTF8 ['(:E-CRLF :UTF8-BASE)] @ #x20116f6a> is a
structure of type EXTERNAL-FORMAT.  It has these slots:
 NAME               (:E-CRLF :UTF8-BASE)
 NICKNAMES          (:UTF8 :UTF-8)
...


I thought the string "UTF-8" would also work because when I try WITH-OPEN-FILE  
with an invalid external format like "UTF-9", an error is thrown, while "UTF-8"
is accepted and no error is raised.


>> (defparameter *template-dispatcher*
>>   (hunchentoot:create-prefix-dispatcher "/template-test/"
>>    (lambda ()
>>      (let* ((html-template:*string-modifier* #'identity)
>>            (rows (loop for i below 49 by 7
>>                    collect
>>                      (list :cols
>>                            (loop for j from i below (+ i 7)
>>                               for string = (format nil "~R" j)
>>                               collect (list :content string 
>>                                             :colorful-style (oddp j))))))
>>           (values (list :rows rows)))
>>        (with-output-to-string (html-template:*default-template-output*)
>>          (html-template:fill-and-print-template
>>           (html-template:create-template-printer #p"foo.tmpl" :external-format "UTF-8")
>>           values))))))
>>
>> [...]
>>
>>  12: ((METHOD STREAM-WRITE-CHAR
>>        (FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM T))
>>       #<FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM @ #x21279e5a> #\?)
>>       Locals:
>>         STREAM = #<FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM @
>>   #x21279e5a>
>>         CHAR = #\?
>>         CHAR = #\?
>>         FLEXI-STREAMS:OCTET = 1044
>>         STREAM = #<FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM @
>>   #x21279e5a>
>
> The condition is signalled when Hunchentoot is trying to write the
> page to the client.  You have to make sure that Hunchentoot knows that
> it's supposed to output UTF-8.  See the examples that come with
> Hunchentoot for how this can be done.  (And you should also set the
> headers accordingly, so the browser knows what to expect.)


Thanks!

For the sake of those who might encounter the same problem:
I added this to my handler function:

  (setf (hunchentoot:reply-external-format) :UTF-8)

This will set the reply-external-format only for the given handler. To
set it globaly use this:

  (setf hunchentoot:*hunchentoot-default-external-format* :UTF-8)





More information about the Html-template-devel mailing list