I have a bunch of maps that describe locations:
(def pizzeria
{
:LocationId "pizzeria"
:Desc "Pizzeria where Timur works"
:Address "Vorgartenstraße 126, 1020 Wien"
:Comment ""
})
(def dancing-school
{
:LocationId "dancing-school"
:Desc "Dancing school"
:Comment "4th district"
})
Some of those maps have :Comment
s, others don't.
I want to create a Clojure function that, among other things, outputs the comment to HTML, if it is present.
I wrote this function:
(defn render-location-details
[cur-location]
(let [
desc (get cur-location :Desc)
address (get cur-location :Address)
comment (get cur-location :Comment)
address-title [:h4 "Address"]
address-body [:p address]
comment-hiccup [
(if (clojure.string/blank? comment)
nil
[:div
[:h4 "Comment"]
[:p comment]
])
]
]
[:h3 desc
address-title
address-body
comment-hiccup
]
)
)
If I run the code that uses this function, I get the error
Execution error (IllegalArgumentException) at
hiccup.compiler/normalize-element (compiler.clj:59).
is not a valid element name.
If I change comment-hiccup
to nil
, the error disappears.
How can I output data to HTML conditionally using Hiccup?
Note: I am new to Clojure, so if my approach is completely wrong, please tell and show how to do it right.