所以我用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是一个函数,它以数字作为数据Id,并通过特定的数据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)如果我更改blogp代码,它似乎与另一个缺陷模板工作得很好。
(html/deftemplate blogp "selmer/blogpage.html"
[]
[:bjudul] (html/content (:Judul (db/findById **1**)))
[:bisi] (html/content (:Isi (db/findById **1**))))然后我输入了这个
(createpage blogp "Blog")效果很好。知道为什么吗?
我是新来的克洛尔,我也是新来的
发布于 2014-11-13 11:37:20
您的layout模板期望content参数是一个函数,而当您执行(blogp id)时,实际上是传递函数的结果,而不是函数本身。你能做的就是这样使用它:
(createpage (partial blogp id) "Blog")https://stackoverflow.com/questions/26901275
复制相似问题