Hi Matthew,
Jay beat you to the answer 8-) [though the list apparently bounced my
reply to him]
I do appreciate your detailed explanation. I knew that I did not need
the html module to use response/xexpr in the web-server, but I was
looking for some syntax to add styling to the content, and I was
searching through every "html" related link in the documentation. I
really wish I could have figured it out on my own.
Thanks,
George
On 8/24/2015 6:13 PM, Matthew Butterick wrote:
I haven't used the HTML module (though it is, AFAICT, intended for
parsing HTML, not writing it). But the examples in the webserver docs
(e.g., `send/back`) don't use that module. Instead, they construct
responses out of X-expressions.
Judging from your example, perhaps you are mixing up the two? (Or
maybe three — the documentation snippet you cited for `style` was from
`scribble/html/html`, which is yet another thing.)
For example, the quasiquoting on this expression makes it an
X-expression, so the tag names (html, body, p) are just quoted
symbols, not structs or functions from another module. So as you've
written it, it won't work.
`(html
(body (list (p "Hello " (b ,username))
(p (style "color:red" ; <- how to do this?
"An error occurred processing your request.))
There's no `list` necessary in an X-expression, and the attributes are
separated. So the correct X-expression syntax would be:
`(html (body (p "Hello " (b ,username))
(p ((style "color:red")) "An error occurred
processing your request.")))
For styling, you have three choices.
1) Apply the styling directly to the tag as an attribute. As shown above.
2) Apply the styling indirectly through an external CSS file, as John
Clements suggested. To do this, you'd need to give your target a
'class' or 'id', and then it would take on whatever styling was
defined in the CSS file, e.g.,
`(html (body (p "Hello " (b ,username))
(p ((class "error")) "An error occurred processing
your request.")))
3) Or, since you don't want an external file, you can apply the
styling indirectly with inline CSS. You'd still need to give your
target a 'class' or 'id', but then the style sheet itself can live
inside the X-expression:
`(html
(style ((type "text/css")) ".error {color: red;}")
(body (p "Hello " (b ,username))
(p ((class "error")) "An error occurred processing your
request.")))
Again, none of these options use external functions. They're just
X-expressions and you can generate them however you like.
--
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.