Whitespace Removal
In-between the tags that GoHT creates it will leave in the whitespace that you have used. This is going to be fine in most cases. However, there are times when you will want to control that whitespace.
Haml uses the greater-than > and lesser-than < characters for whitespace removal. Slim uses those markers for whitespace addition. EGO uses tag-level controls such as <%-, -%>, and $%>.
The removal examples below apply to Haml templates.
Removing Whitespace Around Tags
To remove whitespace outside of tags, you can use the greater-than > character.
renders as:
The middle paragraph removed the surrounding whitespace, so now all three paragraphs are on the same line.
Had it been the last paragraph that had the greater-than > character, then the whitespace after the paragraph would have been removed.
it would have rendered as:
Removing Whitespace Inside Tags
To remove whitespace inside tags, you can use the lesser-than < character.
renders as:
There is no difference in the above and this:
renders as:
You’re more likely to want to remove the whitespace between tags when you are nesting them.
renders as:
The whitespace between the p and span tags has been removed but the whitespace inside the span tag has been left in place.
Combined
You can use both the greater-than > and lesser-than < characters together. The order that you use them will not matter. Use <> or >< as you see fit.
renders as:
We’ve removed the whitespace outside the span tag because it used the greater-than > character, and we’ve removed the whitespace inside the span tag because it used the lesser-than < character.
Slim Whitespace Addition
Slim uses > and < to add whitespace around or inside a tag.
Use the markers according to the Slim output you want; they are not Haml-style removal controls.
EGO Whitespace Controls
EGO can strip whitespace at tag boundaries:
<%- strips leading whitespace for the opening tag, -%> strips whitespace at the closing tag, and $%> strips one following newline.