だから私は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))))
(注: データIDdb/finddata 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 コードを変更すると、別の deftemplate で問題なく動作するようです
(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も初めてです