Filters
Filters are a way to add a large block of content to a Haml or Slim template. This is useful for adding content that is not HTML, such as CSS or JavaScript. Filters are added to the template using the colon : character followed by the name of the filter.
| Filter | Haml | Slim | EGO |
|---|---|---|---|
:plain | Yes | No | Use normal HTML/text |
:escaped | Yes | No | Use escaped output <%= value %> |
:preserve | Yes | No | Use normal HTML/text |
:javascript | Yes | Yes | Use <script> |
:css | Yes | Yes | Use <style> |
EGO templates do not use filter syntax because they already use normal HTML.
CSS
The :css filter is used to add CSS to your templates. The CSS content is added to the template as is.
renders as:
The :css filter also supports interpolation.
JavaScript
The :javascript filter is used to add JavaScript to your templates. The JavaScript content is added to the template as is.
renders as:
The :javascript filter also supports interpolation.
Plain text
The :plain filter is used to add a block of plain text to your templates. Interpolated values and expressions will be unescaped. Meaning if you include HTML in the values, then you will be getting HTML in your output.
renders as:
Escaped text
The :escaped filter is used to add a block of escaped text to your templates.
All plain text, interpolated values, and expressions will be escaped.
renders as:
Preserved text
The :preserve filter is used to add a block of preserved text to your templates. Like the :plain filter, interpolated values and expressions will be unescaped. The newlines and leading whitespace will be preserved.
renders as: