(define (login-template (login-error ""))
`(html
(head
(link ((rel "icon") (href "data:,")))
(title "Please login"))
(body
(form ((action "") (method "post"))
(label ((for "username")) "Username:")
(input ((type "text") (name "username") (maxlength "64")))
(label ((for "password")) "Password:")
(input ((type "password") (name "password") (maxlength "64")))
(button ((type "submit") (value "Login")) "Login"))
,(cond
((not (eq? login-error "")) `(p, login-error))
(else '(p "Enter your username/password."))))))
(define (login-template (login-error ""))
`(html
(head
(link ((rel "icon") (href "data:,")))
(title "Please login"))
(body
(form ((action "") (method "post"))
(label ((for "username")) "Username:")
(input ((type "text") (name "username") (maxlength "64")))
(label ((for "password")) "Password:")
(input ((type "password") (name "password") (maxlength "64")))
(button ((type "submit") (value "Login")) "Login"))
,(cond
((not (eq? login-error "")) `(p, login-error))))))
One possible way is to have the first case returns a list of one element, and the else case returns an empty list. You then splice this list into body
via ,@.
`(body
(form ((action "") (method "post"))
(label ((for "username")) "Username:")
(input ((type "text") (name "username") (maxlength "64")))
(label ((for "password")) "Password:")
(input ((type "password") (name "password") (maxlength "64")))
(button ((type "submit") (value "Login")) "Login"))
,@(cond
[(not (eq? login-error "")) `((p ,login-error))]
[else '()]))
If the then branch is taken, the value will be:
`(body
(form ((action "") (method "post"))
(label ((for "username")) "Username:")
(input ((type "text") (name "username") (maxlength "64")))
(label ((for "password")) "Password:")
(input ((type "password") (name "password") (maxlength "64")))
(button ((type "submit") (value "Login")) "Login"))
(p ,login-error))
On the other hand, if the else branch is taken, the value will be:
`(body
(form ((action "") (method "post"))
(label ((for "username")) "Username:")
(input ((type "text") (name "username") (maxlength "64")))
(label ((for "password")) "Password:")
(input ((type "password") (name "password") (maxlength "64")))
(button ((type "submit") (value "Login")) "Login")))
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/48f5b3c7-3ec2-43cc-8f01-60e36acb1e74%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.
Well, you can always use macro!
(define-syntax-rule (when/splice test body ...)
(if test (list (begin body ...) '())))
`(body
(form ((action "") (method "post"))
(label ((for "username")) "Username:")
(input ((type "text") (name "username") (maxlength "64")))
(label ((for "password")) "Password:")
(input ((type "password") (name "password") (maxlength "64")))
(button ((type "submit") (value "Login")) "Login"))
,@(when/splice (not (eq? login-error ""))
`(p ,login-error)))
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/1286c435-bbff-4b0a-8a3a-eb1ccf731b27%40googlegroups.com.
Actually you might want to use (list (let () body ...))
rather than (list (begin body ...))
so that you can use define
inside when/splice
, just like how you can do that in when
.