dev-resources.site
for different kinds of informations.
Common Lisp HTML templates: using Djula in .lisp files
Published at
1/2/2025
Categories
lisp
commonlisp
Author
vindarel
;;;
;;; How to use Djula templates in-file, without separate file templates.
;;;
;;; This can make it easier to ship your app as a single binary.
;;; Otherwise, see
;;; https://lisp-journey.gitlab.io/blog/lisp-for-the-web-build-standalone-binaries-foreign-libraries-templates-static-assets/#embed-html-djula-templates-in-your-binary
;;;
;;; We use two Djula functions:
;;; - compile-string
;;; - render-template*
;;;
;;;
#++
(ql:quickload '("djula" "pythonic-string-reader"))
(pythonic-string-reader:enable-pythonic-string-syntax)
(defparameter *template-hello* """
{% if foo %}
foo is true
{% else %}
foo is false
{% endif %}
""")
(defun render (s &rest keys)
(apply
#'djula:render-template*
(djula:compile-string s)
nil
;; key arguments:
keys
))
#++
(render *template-hello* :foo t)
;; =>
" foo is true "
Articles
12 articles in total
Common Lisp HTML templates: using Djula in .lisp files
currently reading
Advent of Code: alexandria's map-permutations was perfect for day 08. Common Lisp tip.
read article
FTP and SFTP clients for Common Lisp
read article
Common Lisp with batteries included: CIEL v0.2 (aka fast scripting with useful libraries)
read article
Common Lisp VS Haskell
read article
Debugging Common Lisp: "Iย feel so much faster and free"
read article
Common Lisp's groupBy is Serapeum:assort
read article
Common Lisp VS C: a testimony
read article
Python VS Common Lisp applied: print, log and icecream
read article
Is Elixir or Common Lisp the best language for building a bootstrapped B2B SaaS in 2024?
read article
Form validation in Common Lisp
read article
Common Lisp GUI with Electron ยท quick how to
read article
Featured ones: