Template Engines ERB, HAML and Slim are all Template Engines. They take some source template and data and produce a formatted output.
ERB (Embedded Ruby) ● ERB is the Ruby language's built-in template engine. ● Uses expression tags <%= ... %> and scriptlet tags <% ... %> ● Useful for embedding Ruby in any kind of source document, most commonly HTML and XML.
ERB - The Good Why is ERB useful? ○ Familiar HTML-style syntax ○ Simple learning curve ○ Easy to figure out what a given tag is doing
ERB - The Bad The problem with using ERB to write HTML is that it takes an already verbose syntax format like HTML and adds even more clutter!
HAML (Hypertext Abstraction Markup Language) HAML is a template engine designed to provide a layer of abstraction above HTML. It uses a clean, concise syntax which compiles down to HTML and offers several usability benefits.
HAML Features DRY! Short, easy tags White-space scoping Filters for other template engines Rails support And much more!
HAML- The Bad ● Parsing is slower than ERB ● The syntax can be minimized further; attributes still require hashes, for example.
Enter... Slim Slim is another lightweight templating engine. Inspired by HAML, Slim offers extended functionality with an arguably more expressive syntax and a quicker compilation speed.
So... which should you choose? Use ERB if... You don't want to learn a new syntax. You need lightning-fast templates. You don't want to add additional gems You don't care for pretty code
So... which should you choose? Otherwise, learn HAML or Slim! Both are excellent choices for what they do. HAML is generally more common. Slim provides better speed and extended functionality. The choice is mostly personal preference.