Haml (haml)¶ ↑
Haml is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ASP, and ERB, the templating language used in most Ruby on Rails applications. However, Haml avoids the need for explicitly coding HTML into the template, because it itself is a description of the HTML, with some code to generate dynamic content. (more
Example¶ ↑
%html
%head
%title= @title
%body
%h1
Hello
= world + '!'
Usage¶ ↑
The Tilt::HamlTemplate class is registered for all files ending in .haml by default. Haml templates support custom evaluation scopes and locals:
>> require 'haml'
>> template = Tilt.new('hello.haml')
=> #<Tilt::HamlTemplate @file='hello.haml'>
>> @title = "Hello Haml!"
>> template.render(self, :world => 'Haml!')
=> "
<html>
<head>
<title>Hello Haml!</title>
</head>
<body>
<h1>Hello Haml!</h1>
</body>
</html>"
Or, use the Tilt::HamlTemplate class directly to process strings:
>> require 'haml'
>> template = Tilt::HamlTemplate.new { "%h1= 'Hello Haml!'" }
=> #<Tilt::HamlTemplate @file=nil ...>
>> template.render
=> "<h1>Hello Haml!</h1>"
NOTE: It’s suggested that your program require 'haml' at load time when using this template engine within a threaded environment.
Options¶ ↑
Please see the Haml Reference for all available options.
See also¶ ↑
Related module¶ ↑
Required files
- haml