How Can I Output an HTML Comment in Compojure/Hiccup?
Asked Answered
D

2

17

I'd like my program to output the following HTML:

<!--[if lt IE 8]><link rel="stylesheet" href="../blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->

Is there a way to output html comment literals with Hiccup?

Dishcloth answered 25/5, 2010 at 14:0 Comment(0)
J
21

Just insert them. Maybe this is a little bit cheating, but it works...

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>
Joy answered 25/5, 2010 at 14:40 Comment(0)
N
3

You got me curious, so I re-read the code: there's no explicit comment function - you would have to pass that as a string literal. But you could do something like:

(defn comment
  "Wrap the supplied HTML in a comment"
  [html]
  (str "<!--" html "-->"))

if you really needed the function (although that's pretty simplistic). You could always add the IE if statement as an optional parameter.

Neutron answered 25/5, 2010 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.