To render our templates, they need be compiled first. We do that with
the COMPILE-TEMPLATE*
function. For inheritance to work, we
need to put all the templates in the same directory so that Djula can
find them when resolving templates inheritance.
Djula looks for templates in the *CURRENT-STORE*
. For our
templates to be found, we have to add the template folder path the
templates store. We can do that with the
ADD-TEMPLATE-DIRECTORY
function.
Here is an example:
(add-template-directory (asdf:system-relative-pathname "webapp" "templates/")) (defparameter +base.html+ (djula:compile-template* "base.html")) (defparameter +welcome.html+ (djula:compile-template* "welcome.html")) (defparameter +contact.html+ (djula:compile-template* "contact.html"))
Then we can render our compiled templates using the RENDER-TEMPLATE*
function:
(djula:render-template* +welcome.html+ s :title "Ukeleles" :project-name "Ukeleles" :mode "welcome")
By default, Djula automatically recompiles the templates when they change.
If you want to disable this, use the *recompile-templates-on-change* variable:
(setf djula:*recompile-templates-on-change* nil)
Adds DIRECTORY
to the search path of the TEMPLATE-STORE
Provides a hook to customize template compilation.
Specializers:
(toplevel-compiler common-lisp:t)
(compiler common-lisp:t)
Compiles template NAME
with compiler in CURRENT-COMPILER
Render TEMPLATE
into STREAM
passing TEMPLATE-ARGUMENTS
Sets djula::*static-path*
to be url
, this allows the static
tag to serve static files from the static url.