DEV Community

Lam
Lam

Posted on

2 2

Haml Cheat Sheet

Ruby

-# 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
Enter fullscreen mode Exit fullscreen mode

Inline Attributes

Either hash syntax works

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

Classes and ID's

%p.class-example
.no-tag-defaults-to-div
%div#butItCanBeIncluded
Enter fullscreen mode Exit fullscreen mode

Tags

%html
  %head
    %title
  %body
    %h1 Hello World
    %br/
Enter fullscreen mode Exit fullscreen mode

Doctype

!!! 5
Enter fullscreen mode Exit fullscreen mode

Reference

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay