published on 03.02.2013 15:27.

Why I really like the Slim template language

I recently discovered the Slim template language. My first thought was: why bother, HAML is already much better than plain HTML/ERB, so there’s really no point in learning yet another template language.

But I still find some things in HAML awkward or hard to remember, so I gave Slim a try on a recent project. Here’s what I found:

  • even less syntax noise, for example: no leading % for HTML tags, cleaner multiline
  • consistent, shorter attribute syntax (see the example here)
  • regular HTML is allowed in templates. Among other things, this helps converting ERB templates by hand.
  • slim/translator: no need to wrap I18n keys in = t(’.your_key’)
  • (claims to be) very fast.
  • after having used it for ~10 templates, there were no weird errors or stuff I couldn’t do.

The only downside I found is that there doesn’t seem to be a reliable HTML/HAML to Slim converter, yet.

You don’t have to actually learn Slim. The syntax is extremely similar to HAML: leave out %, (), {} and ”” in most places, and you get Slim. Where not, things can be looked up in the documentation just as quickly as for HAML.

Replacing HTML/ERB with HAML still is the biggest win, but Slim is the better HAML to me. I’ll be playing with it on a side project (shameless plug) and may use it from the start for the next big one.

Update:

Two real world examples:

Posted in ,  | no comments | no trackbacks