htmlclojureenlive

Clojure Enlive: Applying snippet on a list


I am trying to define an enlive template for a html table, that shows data from a map. template-div for this example is right here. Dummy content that for the cells in the template is here.

defsnippet for cell value and deftemplate are defined as:

(require '[net.cgrand.enlive-html :as html])

(html/defsnippet value-cell (template-div) [:div.Row :div.Cell] [value]
          (html/content value))

However, when I try the snippet

(value-cell (mapv vals (:event-data dummy-content)))

All the values are in one tag like this

({:tag :div, :attrs {:class "Cell"}, 
:content ("end time 1" "date 1" "event name 1" "start time 1"  "performer 1" "end time 2" "date 2" "event name 2" "start time 2" "performer 2")})

And I need every item from a list to be a value in the tag.


Solution

  • You are passing a list of values to value-cell, so value-cell should look something like:

    (html/defsnippet value-cell (template-div)
      [:div.Row :div.Cell]
      [values]
      (html/clone-for [value values]
                      (html/content value)))