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.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

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.