getting-started
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.hamlYour 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