Clojure Selmer Basics

Eventually I’ll finish this, … maybe.

Want to make advanced web pages? Try Selmer. Selmer is a powerful templating system that saves time and money during complex website development.

Selmer is a Clojure based templating system that not too surprisingly works great with Luminus framework. We’ll use Luminus to host our Selmer examples, because it is easy to get running fast.

Prerequisite: Leiningen

Begin with the command …

Now you have a fully functional server with Selmer templates preconfigured. (Told you it was easy.)

cd  into your project root

Run your new server.

In a web browser visit http://localhost:3000/ You should see something similar to the following.

Default Selmer Template
The default Selmer template included in a Luminus project.

The web page you are looking at is a Selmer template.

Explaining Selmer

Selmer is a templating language for creating web pages. Selmer integrates with Clojure. Clojure is one of the most concise and powerful general-purpose computer programming languages available. How concise is Clojure? There are many examples of Clojure rewriting common Java and Python functions of 10-20 lines as one line of Clojure code. Selmer templates get to take advantage of Clojure when creating web pages.

For those new to templated web pages, …

The very simplest web pages are written in HTML. If all you need to do is present a restaurant menu, a short list of services, or a description of  some research, simple HTML may be enough for you. More advanced and complex web pages often have information that changes based off external factors. For example, if a user of your website needs to log in to see information, a Selmer template can change the information on the page to match the information that user should see. Or if users visiting the page from a different country should see a custom price list, Selmer templates can help with displaying custom information based off regions of the visitors. Selmer templates can also leverage session information to help users of your website navigate more easily to find the information they need.

From a technical view, Selmer templates create enough of a Separation Of Concerns (SoC) that you can hire less expensive junior developers to layout your website and have more expensive senior developers handle the complex server and database code. Using Selmer templates saves your business money, because senior developers are not entangled in tasks that junior developers can handle.

To be fair, there are tons of templating systems associated with various languages and servers. All have similar benefits, except very few exploit the power of Clojure.

Taking the Guided Tour

Above, we created a web server in a Luminus Clojure project with Selmer templates. Let’s have a look around the Selmer related bits-and-pieces of our project.

I suggest opening the mycoolapp  project in Visual Code or your favorite code editor.

A Little Code

Let’s add a Selmer template just to get started.