Clojure enlive: the function html-content can't operate a function with an argument (?)

92 views Asked by At

So i made a simple html template using deftemplate,

(html/deftemplate header "selmer/header.html"
  [])    

(html/deftemplate footer "selmer/footer.html"
  [])

(html/deftemplate blogp "selmer/blogpage.html"
  [id]
  [:bjudul] (html/content (:title (db/finddata id)))
  [:bisi] (html/content (:content (db/finddata id))))

(Note: db/finddata id is a function that takes a number as a data Id and returns a map of data from my database by a certain data id, for example if i type

(db/finddata 1)   

it will produce this

{:title "Wowtitle", :content "wowcontent", :id 1}

it is a data from my database with an id of 1)

and then

(html/deftemplate layout "selmer/layout.html"
  [content contenttitle]
  [:title] (html/content contenttitle)
  [:header] (html/html-content (apply str (header)))
  [:pagecontents] (html/html-content (apply str (content)))
  [:footer] (html/html-content (apply str (footer))))

(defn createpage [pcontents tcontent]
  (apply str (layout pcontents tcontent)))

but when i type this in repl

(createpage (blogp id) "Blog")

it produces this error

ClassCastException clojure.lang.PersistentVector$ChunkedSeq cannot be cast to clojure.lang.IFn  zenblog.pageandctrl.pagelayout/fn--14851/fn--14853/fn--14854 (form-init2686073120612682758.clj:1)

it seems worked just fine with another deftemplate, for example if i change the blogp code

(html/deftemplate blogp "selmer/blogpage.html"
  []
  [:bjudul] (html/content (:Judul (db/findById **1**)))
  [:bisi] (html/content (:Isi (db/findById **1**))))

and then i typed this in repl

(createpage blogp "Blog")

it worked just fine. Any ideas why?

im new to clojure and im new to enlive as well

1

There are 1 answers

0
Ankur On BEST ANSWER

Your layout template expect the content param to be a function whereas when you do (blogp id) you are actually passing the result of the function and not the function itself. What you can do is use it like this:

(createpage (partial blogp id) "Blog")