O'Reilly logo

Learning Sinatra by Manoj Sehrawat, Sudeep Agarwal

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

Writing haml templates

The HTML Abstraction Markup Language (HAML) is a templating language that helps write clean and simple HTML templates. haml produces HTML when processed and also provides you with the scope to write inline Ruby statements.

Some basic things to keep in mind while writing haml templates are as follows:

Use % to define any HTML tag, such as %table for <table> or %head for <head>.

  • Use two spaces of indentation to define child elements and autogenerate closing tags
  • Use a hash to add HTML attributes, such as %form{name: "some-form"}
  • Use . to add a class and # to add an ID instead of explicitly specifying them in the hash, such as %form.form#signup for <form class="form" id="signup"> instead of %form{class: "form", id: "signup}
  • Instead ...

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