As you can see, it just looks really, really nice. I think I’m going to try using it for the next few projects and so far I’m really liking it.

Get It

To use Slim, all you need to do is install the gem:

sudo gem install slim

Then require it in your Sinatra app:

require 'slim'

Escaping HTML

One gotcha that you need to watch out for is that all dynamic HTML is made ‘safe’ by default. This means that all html tags are escaped. This can cause havoc with your paritals, but it is easy to get round - just use the double equal ==.

You can also stop the HTML escaping by changing the default setting:

set :slim, :auto_escape = false

Comments

You can add comments to your code using / and HTML comments using /!:

/ This is a comment and won't be in the output
/! This comment will be in the output but as a HTML comment

Logic-Less

It also has a nice logic-less mode that only renders code if it exists.

Eg.

-post
h1 = title

This will only render the h1 tag if the post object has a title - nice!