1

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.

1 Answer 1

1

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)))
Sign up to request clarification or add additional context in comments.

8 Comments

yes this is it, I was playing with clone-for but couldn't figure it out.
Oh, and also, how to put the data from each map into separate row, because this (html/deftemplate mshp (index) [cont] [:div.Row] (html/content (map value-cell (mapv vals (:event-data dummy-content))))) doesn't work?
it is the same problem. What you are telling enlive is "change the content of :div.Row for ...". What you want to tell it is "create one like :div.Row for each", which would translate for a clone-for
yes, but, how to apply clone-for on every map, I need clone-for for cell, and then clone-for for row?
If I understand you correctly, you want one :div.Row per entry on the map, not one :div.Cell per entry. If this is the case, what you want to clone is the whole :div.Row, so your value-cell snippet should be called, value-row and be something like (... [:div.Row] [event-data] (clone-for [[k v] event-data] [:div.Cell] (content v)))
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.