[racket] how to display formlets inside templates

From: keydana at gmx.de (keydana at gmx.de)
Date: Sat Jan 7 12:06:05 EST 2012

Thanks so much Jay, that helps :-)

Ciao,
Sigrid


Am 06.01.2012 um 19:57 schrieb Jay McCarthy:

> formlet-display returns a forest of xexprs
> 
> Templates are about writing the text directly as a string.
> 
> Whenever you want to include any non-string content in a template,
> you'll need to render it as a string. In the case of the result of
> formlet display, that means something like
> 
> @in[xe (formlet-display f)]{ @(xexpr->string xe) }
> 
> or just
> 
> @(map xexpr->string (formlet-display f))
> 
> Jay
> 
> On Fri, Jan 6, 2012 at 9:08 AM, keydana at gmx.de <keydana at gmx.de> wrote:
>> Hi,
>> 
>> sorry for coming with a web server-related question again already, but I have problems figuring out how to display formlets inside templates.
>> I've tried several ways, the latest being:
>> 
>> ...
>> (send/suspend/dispatch
>>   (lambda (make-url)
>>     (get-main-template #:title "start"
>>                                       #:main (include-template "choose-db-form.html")))))
>> 
>> 
>> where I have one function providing the "general html template":
>> 
>> (define (get-main-template #:title (title "") #:top (top "") #:left (left "") #:main (main "") #:right (right "") #:footer (footer ""))
>>  (response/full
>>      200 #"Okay"
>>      (current-seconds) TEXT/HTML-MIME-TYPE
>>      empty
>>      (list (string->bytes/utf-8 (include-template "main.html")))))
>> 
>> 
>> and include a sub-template for the body, which should contain a form provided by a formlet looking like this:
>> 
>> (define f-choose-db
>>  (formlet
>>   (#%# ,((radiogroup-input '(orcl rndba)) . => . db)
>>        ,(input-string . => . user)
>>        ,(input-string . => . pw)
>>        ,((submit #"submit") . => . sm))
>>   (list db user pw)))
>> 
>> 
>> As the sub-template, I've tried
>> 
>> <div>
>> <p>@|errortext|</p>
>> <form action="@(make-url connect-handler)">
>> @(formlet-display f-choose-db)
>> </form>
>> </div>
>> 
>> which I understand does not look like it could work - formlet-display, when called alone, displaying with parentheses and not as html - but still I don't know how to do it - for example, I cannot call xexpr->xml on the displayed formlet because it's not an xexpr...
>> 
>> Could someone give me a hint how to do it?
>> 
>> Many thanks in advance,
>> Sigrid
>> 
>> 
>> ____________________
>>  Racket Users list:
>>  http://lists.racket-lang.org/users
> 
> 
> 
> -- 
> Jay McCarthy <jay at cs.byu.edu>
> Assistant Professor / Brigham Young University
> http://faculty.cs.byu.edu/~jay
> 
> "The glory of God is Intelligence" - D&C 93




Posted on the users mailing list.