Getting Started
Project layout#
A typical project that uses Template::HAML keeps its templates under an app/views/ (or any other) directory, organized by controller / feature, with the .html.haml extension:
my-project/
├── lib/
│ └── MyApp.rakumod
└── app/
└── views/
├── home/
│ └── index.html.haml
└── layouts/
└── app.html.haml
Your first template#
Create hello.haml:
%html
%body
%h1 Hello, world
%p.lead This page was rendered by Template::HAML.
Render it from Raku:
use Template::HAML;
my $html = HAML.render(:src(slurp 'hello.haml'));
say $html;
You should see:
<html>
<body>
<h1>Hello, world</h1>
<p class='lead'>This page was rendered by Template::HAML.</p>
</body>
</html>
Rendering from a string#
HAML.render takes any string, so you can also embed templates inline:
my $src = q:to/HAML/;
%section.container
%h1 Title
%h2 Subtitle
HAML
say HAML.render(:$src);
Where to go next#
- Tags — element names, sigils, class and id shorthand
- Attributes — hash-style attribute syntax
- Indentation — how nesting works
- API — the public Raku API