Usage

To render our templates, they need to 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")

API

function (add-template-directory directory &optional (template-store *current-store*))

Adds DIRECTORY to the search path of the TEMPLATE-STORE

generic (compile-template compiler name &optional error-p)

Provides a hook to customize template compilation.

Specializers:
  • (toplevel-compiler common-lisp:t)

  • (compiler common-lisp:t)

function (compile-template* name)

Compiles template NAME with compiler in CURRENT-COMPILER

function (render-template* template &optional stream &rest *template-arguments*)

Render TEMPLATE into STREAM passing TEMPLATE-ARGUMENTS