Amogh Talpallikar
Amogh Talpallikar

Reputation: 12184

How to repeat a list of items from a vector in hiccup?

If I have a vector name-lst as ["John" "Mary" "Watson" "James"],

and I want to diplay them as list items, how do I do that using hiccup ?

something like

[:ul 
  (for [name name-list]
    [:li name])]

will return a list of [:li ] in between [:ul ] instead of just repeating. There must be something better. I am relatively new to hiccup, I searched but couldn't find anything.

Upvotes: 2

Views: 651

Answers (1)

ponzao
ponzao

Reputation: 20934

Once you feed the data structure to Hiccup you should get the expected result:

(require '[hiccup.core :refer [html]])

(def names
  ["John" "Mary" "Watson" "James"])

(html [:ul 
       (for [name names]
         [:li name])])
;=> "<ul><li>John</li><li>Mary</li><li>Watson</li><li>James</li></ul>"

Upvotes: 3

Related Questions