Adding unique key to li tag in Clojure and Hiccup using a word and index as key

107 Views Asked by At

I have a quick question. I'm working on a Clojure project. I want to add unique key to each li tag, like this:

(defn test [text]
    [:li {:key :index} text])

How I can set keys like "hi+index"?

I tried

{:key (str "hi" index)}

but it does not working. I'm new to Clojure and hiccup.

Thank you very much.

1

There are 1 best solutions below

0
On

You are making a mistake somewhere. When in doubt, ask the computer with some test code:

  (doseq [idx (range 5)]
    (prn (str "hi-" idx)))

with result

"hi-0"
"hi-1"
"hi-2"
"hi-3"
"hi-4"

I like to use this template project for quick tests like the above. Just clone it and throw some sample code into the test/clj/tst/demo/core.clj file, and away you go!