As mentioned in the comments, deftemplate
is a macro that defines the template as a function in your namespace - only once, when it's first evaluated. You can easily write some code to lazily create the templates, and eliminate some of the overhead by caching the template once it's created:
(def templates (atom {}))
(defmacro defservertemplate [name source args & forms]
`(defn ~name [& args#]
(let [src# (get-template ~source)]
(dosync
(if-let [template# (get templates src#)]
(apply template# args#)
(let [template# (template src# ~args ~@forms)]
(swap! templates assoc src# template#)
(apply template# args#)))))))
In your case you'd then be able to say (defservertemplate base "/base.html"...
.
You can probably tidy this up a bit. All you really need to know is that deftemplate
just calls template
, and you can use that directly if you want.