2

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

murtaza52
  • 46,887
  • 28
  • 84
  • 120

3 Answers3

3

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" [] .....)

Sid Kurias
  • 172
  • 2
  • 7
  • 1
    Thanks Sid, that works like a charm. Used the following lein option to spec > :resource-paths ["src/main/resource"] – murtaza52 Sep 12 '12 at 10:37
  • If you go with the conventions, you won't need to specify a full path; besides, that is verbose and duplicative. – David J. May 27 '13 at 01:37
1

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 ) )
Assen Kolov
  • 4,143
  • 2
  • 22
  • 32
1

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))
David J.
  • 31,569
  • 22
  • 122
  • 174