【发布时间】:2014-11-13 19:37:20
【问题描述】:
所以我用deftemplate做了一个简单的html模板,
(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))))
(注意:db/finddata id 是一个函数,它接受一个数字作为 data Id,并通过某个 data id 从我的数据库中返回一个数据映射,
例如,如果我输入
(db/finddata 1)
它会产生这个
{:title "Wowtitle", :content "wowcontent", :id 1}
它是来自我的数据库的数据,id 为 1)
然后
(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)))
但是当我在 repl 中输入这个时
(createpage (blogp id) "Blog")
它会产生这个错误
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)
它似乎与另一个 deftemplate 配合得很好,例如,如果我更改 blogp 代码
(html/deftemplate blogp "selmer/blogpage.html"
[]
[:bjudul] (html/content (:Judul (db/findById **1**)))
[:bisi] (html/content (:Isi (db/findById **1**))))
然后我在repl中输入了这个
(createpage blogp "Blog")
它工作得很好。任何想法为什么?
我是 clojure 的新手,我也是 enlive 的新手
【问题讨论】: