Haml Cheat Sheet

From WikiOD

Here is the cheatsheat of Haml and basic guide on how to use Haml

Doctype[edit | edit source]

!!! 5

Tags[edit | edit source]

%html
  %head
    %title
  %body
    %h1 Hello World
    %br/

Classes and ID’s[edit | edit source]

%p.class-example
.no-tag-defaults-to-div
%div#butItCanBeIncluded

Inline Attributes[edit | edit source]

Either hash syntax works

%meta{ name: "viewport", content: "width=device-width, initial-scale=1.0" }
%input{ :type => "text", :required => true }

Ruby[edit | edit source]

-# This is a comment
-# Anything starting with a hyphen signals to Haml that Ruby is coming
- @arr = [1, 2, 3]
- @str = "test"
-# Equal signals output
= render partial: "shared/header"
= yield
= link_to page_url

Credit:rstacruz