Skip to content

Instantly share code, notes, and snippets.

@arnaud-lb
Created August 25, 2012 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaud-lb/3469893 to your computer and use it in GitHub Desktop.
Save arnaud-lb/3469893 to your computer and use it in GitHub Desktop.
MtHaml attributes example
/ --------------------------------------------------
/ when value is false (or null), attr isn't rendered
/ --------------------------------------------------
%input(type="checkbox" checked=false)
%div(class=(false ? false : "test"))
/ <input type="checkbox" />
/ <div></div>
/ ----------------------------------------------------
/ when value is true, attr is rendered as boolean attr
/ ----------------------------------------------------
%input(type="checkbox" checked=true)
/ html5:
/ <input type="checkbox" checked />
/ xhtml:
/ <input type="checkbox" checked="checked" />
/ ----------------------------------------------------
/ data attrs
/ ----------------------------------------------------
%div(data={foo: "bar", bar: "baz", qux: false ? false : "test"})
/ <div type="checkbox" data-foo="bar" data-bar="baz"></div>
/ ----------------------------------------------------
/ ids
/ ----------------------------------------------------
%div#foo(id=["bar", "baz", false ? false : "test"])
/ <div id="foo_bar_baz" />
/ ----------------------------------------------------
/ classes
/ ----------------------------------------------------
%div.foo(class=["bar", "baz", false ? false : "test"])
/ <div class="foo bar baz" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment