Back to templates

Template details

HTML-TEMPLATE

Portable Common Lisp library for filling templates with string values at runtime, featuring closure-based rendering and intelligent caching.

About this template

HTML-TEMPLATE is a portable Common Lisp library that fills templates with arbitrary string values at runtime to produce text output, most commonly HTML. It is loosely modeled after the Perl module HTML::Template and partially compatible with its syntax, though both libraries contain extensions the other does not support.

What is HTML-TEMPLATE?

HTML-TEMPLATE is a portable library for Common Lisp that accepts templates containing placeholders and substitutes arbitrary string values into them at runtime. The output is a string that can serve as an HTML page or any other text format. The library compiles templates into efficient closures that can be re-used many times, and an intelligent cache mechanism recompiles templates automatically when they change. It is part of the EDICL project and its full documentation is available at https://edicl.github.io/html-template/.

Key Features

  • Portable across Common Lisp implementations — the library is designed to run in standard Common Lisp environments without implementation-specific code.
  • Closure-based rendering — each template is translated into a closure that can be called repeatedly with different values, avoiding re-parsing.
  • Intelligent caching — templates are recompiled automatically when updated, so changes take effect immediately while the program is running.
  • HTML::Template compatibility — the syntax is partially compatible with the Perl module HTML::Template, easing migration for developers from Perl.
  • Output format agnostic — although the name suggests HTML, the library does not enforce HTML; any text output is possible.

Who should use HTML-TEMPLATE?

  • Common Lisp web developers who want a way to generate dynamic HTML from template files directly in Common Lisp.
  • Teams maintaining long-running Lisp services that need to change templates without restarting the application.
  • Developers coming from Perl who already know HTML::Template and want a similar workflow in Common Lisp.

What can you do with HTML-TEMPLATE?

  • Generate HTML pages — fill a base template with dynamic values such as user names, product details, or database results for each request.
  • Produce non-HTML text — create plain-text emails or configuration files using the same template-filling mechanism.
  • Iterate on markup quickly — edit template files on disk and have the next render reflect those edits because the cache detects the change.

How does HTML-TEMPLATE work?

HTML-TEMPLATE parses a template and compiles it into a closure that takes variable bindings as input and returns the fully substituted string. The intelligent cache watches template files, so when a template is modified, the library recompiles it automatically. The resulting render functions are efficient enough to be reused across many requests.

FAQ

Is HTML-TEMPLATE only for generating HTML?

No. The library works with any text output; HTML is just the most common use case. You can use it for plain text, emails, or any structured text format.

Is HTML-TEMPLATE compatible with Perl's HTML::Template?

It is loosely modeled after HTML::Template and shares part of its syntax. However, each library has extensions the other lacks, so complete compatibility is not guaranteed.

Can I change templates without restarting my Lisp process?

Yes. The intelligent cache recompiles templates as soon as they change, so the next call to a render function uses the updated version.

screenshot of HTML-TEMPLATE on template0.com