A simple weblocks application


I’ve been following the Weblocks web framework for about a year now, and it’s my opinion that Weblocks is the best Common Lisp web framework available. One of the difficulties with Weblocks right now is a lack of documentation and example code. This will be a contribution to that need. I have created a simple blog application based on Weblocks. I started with the blog that Evan Monroig put together as a simple tutorial, but wanted to go a little further with it. This will be a multi-part screencast tutorial, but rather than spreading it across multiple posts, I”ll just update this one as I have new material to post. I apologize in advance if there are very dry moments in these videos; I’m new to screencasting and am using free tools. You get what you pay for :-)

So let’s start…


I use the Linux-Emacs-Slime-SBCL stack for the screencasts.  Slime, Emacs, and SBCL are functional on Windows, but I don’t know that Weblocks (or, more importantly, it’s dependencies) will.  I haven’t tried.  I prefer Franz’ Allegro Common Lisp, but Weblocks is targeted specifically at the Hunchentoot webserver. There is a very good Lisp environment screencast by Marco Berringer, and an accompanying reference by Peter Christensen.  I highly recommend them for learning more about how to get your Lisp environment set up. There are many other references on the web that will help you with getting Lisp set up on your machine.  I use the Gentoo distribution of Linux.  Gentoo has a very good package management system called “Portage”, which works something like the FreeBSD/OpenBSD ports system, but better (there are also drop-in replacement systems that improve on Portage in different ways, but I haven’t had a need for them; Portage works just fine for me).  One of the more recently developed features of Portage is the concept of “overlays”, which provide the ability to more easily customize the set of packages available at a particular location or over a particular subset of categories.  There is a Common Lisp overlay that provides fairly up-to-date releases of most of the useful Common Lisp libraries available (the overlay contains 200+ ebuilds), and I’ve found that to be adequate for my needs.  Thus I avoid all the teeth-gnashing over Lisp library management and installation. For me, I just needed to install Emacs, Slime, paredit, SBCL and finally Weblocks (which pulls in a lot of other libraries as dependencies) through the portage system.  The only thing I needed to do to make things work was to edit my .emacs and .swank.lisp files.   My .emacs file needed this:

(load "/usr/share/emacs/site-lisp/site-gentoo" nil t)

and my .swank.lisp (the user lisp initialization file for swank, the Slime backend).

(defun project-setup ()
  (mapcar #'(lambda (path)
              (push path asdf:*central-registry*))

As you can tell (hopefully), the PROJECT-SETUP function merely adds my local project directories to the ASDF path so I can simply use (require :simple-blog) to load my application (SBCL’s REQUIRE function uses ASDF to find packages). The two directories I’m adding to the ASDF path are key to this tutorial:  I am a Weblocks contributor (barely), so I run a local development version of Weblocks in my project directory.  Most users can just install Weblocks however is best supported by their Linux distribution, through ASDF-INSTALL, or manually.  This tutorial was created and tested on the latest development version.  It may or may not work on the last stable (0.8, I think).  Also, I added the ‘simple-blog’ directory to the list because that’s where we will create our application.

Creating a Weblocks Application

After making sure my Lisp environment is set up, I can start everything up:

At this point, we have the skeleton of a Weblocks application. It only writes a little text on the site, but all the plumbing is in place. Since we’re building a blog, we need to design a simple object model to represent it:

Now we have our object model in place and have shown how to use gridedits and default views for viewing and data entry, as well as the limits of the default views. In order to successfully input data, we need to customize the form views:

Now that we have data entry working, we need to build more interesting pieces of our blog. Firstly, how do we display a post to a user? We can write a custom widget to do that:

We’d like to be able to show more than one post to a user. We’ll construct a custom widget to represent the blog itself:

Check back for updates….when I get time, I’ll post screencasts to demonstrate further improvements to the blog, including graphical styling, navigation, author login, and tags.


  • nobody
    February 21, 2009 - 10:09 pm | Permalink

    Looks nice Ben. Thanks.

  • February 22, 2009 - 4:18 pm | Permalink

    Thanks so much for posting this! I tried to work through the blog tutorial before, but had some trouble understanding what was going on. This is very helpful.

  • February 22, 2009 - 6:22 pm | Permalink

    I’m very gratified to hear that it helped you. Be sure and post any feedback you have, so I can improve my screencasting skills :-)

  • Bartosz
    March 14, 2009 - 3:26 pm | Permalink

    Hi, while this is awesome work, it is unreadable in the current sized player. When I set this to fullscreen I can read the text, but the switching between the screencast and emacs closes the fullscreen mode. This really blows – so do you have this available for download? I'd really appreciate this.

  • March 14, 2009 - 10:37 pm | Permalink

    Bartosz, I’ll look into a solution for the problem you pose. It’s very tricky – If you post videos that are sized too large, then it screws up the blog formatting, but as you say, at smaller sizes it’s unreadable. Perhaps I’ll figure out a way to post a separate page.

  • May 5, 2009 - 7:05 pm | Permalink

    I usually dont post in Blogs but your blog forced me to, amazing work.. beautiful

  • September 10, 2009 - 9:25 am | Permalink

    What theme is this?

  • September 17, 2009 - 1:14 pm | Permalink

    Charles, this is the “Japanese Fleur theme design by Lorelei and Web Hosting Geeks for Debt & Free Encyclopedia”. Links in the footer.

  • Phil
    October 22, 2009 - 4:58 pm | Permalink

    Stupid question, the auto completion you where using in the vids, like where a slot’s code just appears out of nothing. What do you need to get that working in emacs?

  • June 14, 2010 - 3:40 am | Permalink

    This an Fantastic post, I will bookmark this in my Digg account. Have a awesome evening.

  • Fabian
    March 25, 2011 - 3:53 pm | Permalink

    Hey Ben,

    thanks for your effort making this fine
    videos. Is it possible to give access to
    the source code. The readability of the source code in the videos is quite bad.


  • Fabian
    March 26, 2011 - 6:49 am | Permalink

    Hi Ben,

    would you be so kind and publish your source code
    of your weblocks blog example?

    Greetings from Germany

  • May 18, 2011 - 12:35 pm | Permalink

    Yes, of course. It should be available at GitHub.

  • August 23, 2011 - 1:18 pm | Permalink

    this is a great weblocks tutorial. I see this was posted in 2009 Do you think you will expand/update it? Also, a discussion of your emacs setup /w slime would be quite interesting. Kudos. You’re using some tricks /w slime that I’m not aware of (yet!) and it’s always interested to see how other lisp developers set up their workflow. :)

  • October 6, 2011 - 1:58 pm | Permalink

    I don’t know. If I find time to, perhaps. I’m not actively developing with it these days, and I find myself prioritizing other things.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>