ERB

Our favorite Ruby templates engine

ERB (Embedded RuBy) is a feature of Ruby that enables you to generate any kind of text from templates. This is the default templating engine for Rails and is the one we favour.

ERB is part of the Ruby standard library. You do not need to install any other software to use it.

ERB copies the text portions of the template directly to the generated document, and only processes code that is identified by markers. Most ERB templates only use a combination of two tag markers, each of which cause the enclosed code to be handled in a particular way.

A tag with an equals sign indicates that enclosed code is an expression, and that the renderer should substitute the code element with the result of the code (as a string) when it renders the template. Use an expression to embed a line of code into the template, or to display the contents of a variable:

Hello, <%= @name %>.
Today is <%= Time.now.strftime('%A') %>.

Tags without the equals sign denote that the enclosed code is a scriptlet. Each scriptlet is caught and executed, and the final result of the code is then injected in to the output at the point of the scriptlet.

Scriptlets are most commonly used for embedding loops or conditional logic into templates:

<% for  @item in @shopping_list %>
  <%= @item %>
<% end  %>

Source: An Introduction to ERB Templating.

Even though some HAML templates are still used in some Prospect.io codebases, you should not create new .haml files. We do favor ERB.

Last updated