Next: , Previous: , Up: Top   [Contents][Index]

3 Usage

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")

Next: , Up: Usage   [Contents][Index]

3.1 Auto-reload

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)

Previous: , Up: Usage   [Contents][Index]

3.2 API

Function: (add-template-directorydirectory &optional (template-store *current-store*))

Adds DIRECTORY to the search path of the TEMPLATE-STORE

Generic Function: (compile-templatecompiler name &optional error-p)

Provides a hook to customize template compilation.


Function: (compile-template*name)

Compiles template NAME with compiler in CURRENT-COMPILER

Function: (render-template*template &optional stream &rest *template-arguments*)


Previous: , Up: Usage   [Contents][Index]