Template engin for Clojure that uses [enlive]
Add following dependency to your project.clj
[enlive-cljhtml "0.0.2"]
(require '[enlive.cljhtml :as template])
Set root directory for template in src (default: nil
)
(template/cljhtml-root "template") ;; -> "src/template"
Set mode (default: :development
)
:production (use template-cache)
(template/cljhtml-mode :production)
:development (read templates every time)
(template/cljhtml-mode :development)
HTML src/template/test.html
<div>abcdefg</div>
:partial
(template/views :partial "test.html")
;; -> parse "<div>abcdefg</div>"
:render (append tag. html,head,body,etc...)
(template/views :render "test.html")
;; -> parse "<html><head></head><body><div>abcdefg</div></body></html>"
HTML src/template/app.html
<html>
<head></head>
<body>
<clojure>(template/html [:h1 "Title"])</clojure>
<clojure>(template/views :partial "test.html")</clojure>
</body>
</html>
defrender macro
(defrender test [data]
;; base template
(template/views :render "app.html")
;; selector & command
[:h1] (template/prepend "Enlive")
[:div] (template/append "hijklmn")
[:div] (template/append
(template/html [:span (:content data)]))))
render macro
(def test
(template/render [data]
;; base template
(template/views :render "app.html")
;; selector & command
[:h1] (template/prepend "Enlive")
[:div] (template/append "hijklmn")
[:div] (template/append
(template/html [:span (:content data)]))))
use
(test {:content "opqrstu"})
output
<html>
<head></head>
<body>
<h1>EnliveTitle</h1>
<div>
abcdefghijklmn
<span>opqrstu</span>
</div>
</body>
</html>
When template file is added
(template/cljhtml-cache)
Copyright © 2014 Daigo Kawasaki (@emanon_was)
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.