Frage

Is it possible to serve a template from outside the source folder in enlive ?

I would like to pickup the templates from my resources/public/templates folder instead of the src/templates folder, how do I do that ?

Thanks, Murtaza

War es hilfreich?

Lösung

Have you tried including the folder that contains your templates in the class path. I believe enlive will look at your classpath to locate the template you specify.
If the resources/public folder is already in your classpath your template path should be similar to

(deftemplate template-name "templates/path/to/template" [] .....)

Andere Tipps

I put all my templates in a file not on the classpath and define them with:

(defmacro deftemplate- [name source & rest]
  `(deftemplate ~name (java.io/File. (str "path-to-pages/" ~source)) ~@rest ) )

Yes, is it possible to serve a template from outside the source folder. In my case, it worked without any changes to my configuration; I have my templates in ./resources and static assets in ./resources/public.

Note: I'm using the following in my project.clj

:min-lein-version "2.0.0"
:plugins [[lein-ring "0.8.3"]]
:dependencies [[org.clojure/clojure "1.5.1"]
               [compojure "1.1.5"]
               [enlive/enlive "1.1.1"]]

I refer to ./resources/index.html like this:

(h/deftemplate index-template "index.html"
  [s]
  [:title] (h/content s))
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top