lundi 3 juillet 2017

Conditionally Show Content or not inside deftemplate macro (Clojure - Enlive)

So far I've managed to figure out how to duplicate a div with clone-for, but I haven't found a function for conditionally applying a transformation, while inside the deftemplate macro.

(deftemplate threads "thread.html" [title xs]
  ;Replace Title
  [:title]
  (content title)
  ;Multiple Post
  [:div.post]
  (clone-for [entry xs]
      (if (contains? entry :ext)
        ([:img#picture] (set-attr :src (str "//images/" title (:tim entry) (:ext entry))))
        ([:div.media-left] (set-attr :style "display:none;")))
      [:div.content :> :strong]
      (content (:name entry))
      [:div.content :> :small#uid]
      (content (:id entry))
      [:div.content :> :small#time]
      (content (time-elapsed entry))
      [:div.content :> :p.post-body]
      (html-content (:com entry))))

returns

java.lang.IllegalArgumentException: Key must be integer

I'm wondering if anyone more experienced with enlive could help? I'm not sure what the following should propely be written as.

  (if (contains? entry :ext)
        ([:img#picture] (set-attr :src (str "//images/" title (:tim entry) (:ext entry))))
        ([:div.media-left] (set-attr :style "display:none;")))

Aucun commentaire:

Enregistrer un commentaire