weavejester/hiccup

:script async

awb99 opened this issue · 1 comments

awb99 commented

html has tags that dont have a value. For example script async.
it seems hiccup does not allow those elements

This is an example what I try to do

(defn script-js [id]
  [:div 
   (str "<script async src='https://www.googletagmanager.com/gtag/js?id=" id " type= 'text/javascript'> </script>")
   ])
(defn script-cljs [id]
  [:script {:async nil
            :type "text/javascript"
            :src (str "https://www.googletagmanager.com/gtag/js?id=" id)}]
  )

The syntax is :async true for tags that don't have a value, but you'll need to ensure that the :mode is set to :html. So:

(html {:mode :html} [:script {:async true}])

Note that if you use the html5 macro, the mode will automatically be set when rendering.