Tutorial

Sytes

Sytes is a small Common Lisp library for building simple websites. I
wouldn't call it a framework—it doesn't deal with any of those things
you'd expect frameworks to do, like handling authentication, database
abstraction etc. Sytes just implements a template engine with a Lispy
syntax and a Hunchentoot dispatcher that maps URLs to templates. Sytes is
the PHP of Common Lisp (I hope this doesn't sound like an insult). If
you're a Lisper, you might enjoy it.

Template syntax

The templates are HTML (we're not limited to HTML, but that's the common
use case) intermixed with Lisp expressions. Sytes implements a parser
which transforms your template into S-expressions which are then compiled
into Lisp closures. The language is not Common Lisp; it's
instead much simpler (think Scheme). Templates are compiled only once,
then the main closure is stored and just executed whenever a request comes
in. Templates are re-compiled only if the file modification time changed
since the cache time.

Essentially, the bracket characters are special, in that they commute the
parser mode. But in those cases where you'd rather use brackets for
something else (such is the case for this page, where I want to type
brackets literally to show you examples) you can customize it using a
special directive.

The filesystem structure

Templates are stored on disk in a directory structure that resembles the
URL shape. Each Syte defines a root directory where templates are stored.
Then, for example an URL like "http://.../foo/bar/baz" is mapped to one of
the following files, depending on how they are found on disk:

ROOT/foo/bar/baz/index.syt (if “baz” is a directory)

ROOT/foo/bar/baz (if “baz” is a file)

ROOT/foo/bar/baz.syt (if “baz” doesn't exist)

Autohandlers / dhandlers

This is an idea I borrowed
from Perl's HTML::Mason module.
Autohandlers are a facility to ease including headers/footers in a
template. For example in a language like PHP, you would need to include
manually header/footer in each template—something I find unpleasant.

Before executing a template, the directory where it resides and any parent
directories up to the Syte ROOT are searched for a file named
“autohandler.syt”. If that file is found it is executed instead of the
template, and inside that file a special function (“call-next”) may be
used to execute the actual template. Autohandlers themselves are subject
to the same treatment (if a parent autohandler exists, it is executed
instead), allowing you to cascade changes to the output into the parent
directories; if you want, it's a simple inheritance mechanism.