plain-text

Plain text and interpolation

Any line whose first non-space character is not a HAML sigil is plain text. Plain text is emitted as-is at the current indent level.

%div
  Hello world
  Another line

renders to:

<div>
  Hello world
  Another line
</div>

Backslash escape

To produce text that begins with a HAML sigil, prefix the line with \. The backslash is stripped from the output.

\%foo
\.bar
\#hash

renders to:

%foo
.bar
#hash

Interpolation

#{ ... } evaluates a Raku expression, HTML-escapes the result, and emits it.

%p Hello, #{ $name }!

with :locals(%(name => 'world')) renders to:

<p>Hello, world!</p>

!{ ... } evaluates and emits the result without HTML-escaping. Use it when the value is already known-safe HTML.

%p !{ $raw }

with :locals(%(raw => '<b>bold</b>')) renders to:

<p><b>bold</b></p>

To produce a literal #{...} or !{...}, escape the leading sigil with a backslash:

%p \#{ literal }

renders to:

<p>#{ literal }</p>

Interpolation is recognized in tag content, plain text lines, and inside double-quoted attribute strings:

%a{ href: "/users/#{ $id }" } Profile

with :locals(%(id => 7)) renders to:

<a href='/users/7'>Profile</a>

Single-quoted attribute strings are literal — no interpolation is performed:

%a{ title: 'Hello #{name}' } go

renders to:

<a title='Hello #{name}'>go</a>

Escaping rules

Inside #{ ... }, the value is HTML-escaped before emission, so user input cannot inject markup:

%p #{ $tag }

with :locals(%(tag => '<b>')) renders to:

<p>&lt;b&gt;</p>

Inside !{ ... }, the value is emitted raw. Inside attribute values, the final attribute value is escaped once after interpolation, so #{} and !{} produce equivalent output for attributes.

Multi-line content

The legacy | line-continuation operator from Ruby HAML 3 is not supported. Wrap multi-line content in a tag or use embedded Raku for formatting:

%p
  First line
  Second line

Template::HAML v0.9.5

HAML template engine

Authors

  • Greg Donald

License

Artistic-2.0

Dependencies

Provides

  • Template::HAML
  • Template::HAML::Actions
  • Template::HAML::CLI
  • Template::HAML::Cache
  • Template::HAML::Codegen
  • Template::HAML::Comment
  • Template::HAML::Config
  • Template::HAML::Context
  • Template::HAML::DirectCodegen
  • Template::HAML::DirectEmit
  • Template::HAML::Doctype
  • Template::HAML::Eval
  • Template::HAML::Filter
  • Template::HAML::Filters
  • Template::HAML::Format
  • Template::HAML::Grammar
  • Template::HAML::Helpers
  • Template::HAML::HelpersRole
  • Template::HAML::Interpolation
  • Template::HAML::Lint
  • Template::HAML::Multiline
  • Template::HAML::Node
  • Template::HAML::Plain
  • Template::HAML::Plugin
  • Template::HAML::Renderer
  • Template::HAML::Statement
  • Template::HAML::Tag
  • Template::HAML::TagTransformers
  • Template::HAML::ViewContext
  • Template::HAML::Visitor
  • Template::HAML::Watch
  • Template::HAML::X

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.