如何在Compojure/Hiccup中输出HTML注释?
题
我希望我的程序输出以下HTML:
<!--[if lt IE 8]><link rel="stylesheet" href="../blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->
有没有办法用打ic输出HTML评论文字?
解决方案
只是插入它们。也许这有点作弊,但它有效...
user=> (html
[:html
[:head
"<!--[if lt IE 8]>"
[:link {:rel "stylesheet"
:href "../blueprint/ie.css"
:type "text/css"
:media "screen,projection"}]
"<![endif]-->"]])
<html><head><!--[if lt IE 8]><link href=\"../blueprint/ie.css\" media=\"screen,projection\" rel=\"stylesheet\" type=\"text/css\" /><![endif]--></head></html>
其他提示
您让我感到好奇,所以我重新阅读了代码:没有明确的评论功能 - 您必须将其作为字符串字面的字面形式传递。但是您可以做类似的事情:
(defn comment
"Wrap the supplied HTML in a comment"
[html]
(str "<!--" html "-->"))
如果你 真的 需要该功能(尽管这很简单)。您可以随时添加IF语句作为可选参数。
不隶属于 StackOverflow