O'Reilly logo

Pragmatic Guide to Sass by Michael Lintorn Catlin, Hampton Catlin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Haml Walkthrough: ERB

Now we’re going to walk you through the exact same process with which Haml was created. A well-formatted bit of HTML was changed step-by-step until Haml was born.

Let’s start with an example using ERB. It’s a pretty standard template you might find in any Ruby project. Don’t panic if you aren’t a Rubyist—it’s a straightforward example.

haml/haml_e1.html
 
<div​ id=”products”​>
 
<%- @products.each do |product| %>
 
<div​ class=”product” id=”product_<%= product.id %​>​”>
 
<div​ class=”name”​>​​<%= product.name %>​​</div>
 
<div​ class=”price”​>​​<%= product.price %>​​</div>
 
</div>
 
<% end %>
 
</div>

Executing this would print out each of the products in @products and assign each one a custom ID like product_23 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required