Skip to content

Instantly share code, notes, and snippets.

@mattwildig
Last active December 15, 2015 18:39
Show Gist options
  • Save mattwildig/5305812 to your computer and use it in GitHub Desktop.
Save mattwildig/5305812 to your computer and use it in GitHub Desktop.
Rendered new haml autoclose/self-closing/empty tags docs

Empty (void) Tags: /

The forward slash character, when placed at the end of a tag definition, causes Haml to treat it as being an empty (or void) element. Depending on the format, the tag will be rendered either without a closing tag (:html4 or :html5), or as a self-closing tag (:xhtml).

Taking the following as an example:

%br/
%meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/

When the format is :html4 or :html5 this is compiled to:

<br>
<meta content='text/html' http-equiv='Content-Type'>

and when the format is :xhtml it is compiled to:

<br />
<meta content='text/html' http-equiv='Content-Type' />

Some tags are automatically treated as being empty, as long as they have no content in the Haml source. meta, img, link, br, hr, input, area, param, col and base tags are treated as empty by default. This list can be customized by setting the {Haml::Options#autoclose :autoclose} option.

@pzi
Copy link

pzi commented Aug 16, 2013

As discussed in this Issue, source and others should be added to the default list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment