Question

I have a list of photo links and would like to generate img tags with clojure and noir.

Here I get the links:

(def photos
(->> (get-in result ["photoset" "photo"]) (map #(str "http://farm"(get % "farm")
".staticflickr.com/"(get % "server")"/"(get % "id")"_"(get % "secret")"_b.jpg"))))

Result:

(http://farm9.staticflickr.com/8087/8455893107_1a3236df06_b.jpg http://farm9.staticflickr.com/8235/8469482476_4c1bf59214_b.jpg)

And then I try to generate img tags from that list:

(defpage "/" []
 (mylayout/layout
 (doseq [e photos] (prn e))
 ))

  (calls (defpartial layout [& content] ...)

I'm trying to get the following output for each link in for a noir based site:

[:img {:src "url"}]

I was trying out this one but without success:

(doseq [e photos] ([:img {:src e}]))

How can I pass the links to the layout so that it generates img tags?

Thanks!

Was it helpful?

Solution

Either of these should work:

(map #(vector :img {:src %}) photos)

(for [url photos]
  [:img {:src url}])

Edit: As Chuck mentioned, doseq is for side-effects. You are wanting to "collect" the results and send them to the template. To do this you need to use list comprehension like for or just map over your collection.

I hate to rain on your parade but just so you know, noir has been deprecated

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top