Questions tagged [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. It can be used as a standalone HTML generation tool or as a template rendering engine in a web framework such as Ruby on Rails or Ramaze. HAML templates are pre-compiled into plain HTML templates which is consumed by a client's web browser to render information sent by the server as a HTML web page.

HAML (HTML Abstraction Markup Language) is an indentation based, terse page description markup. It features among other things autoclosing of tags and convenient shorthands to set class and id attributes.


Example

page and its conversion :

erb

<div id='content'>
  <div class='left column'>
    <h2>Welcome to our site!</h2>
    <p><%= print_information %></p>
  </div>
  <div class="right column">
    <%= render :partial => "sidebar" %>
  </div>
</div>

HAML

#content
  .left.column
    %h2 Welcome to our site!
    %p= print_information
  .right.column
    = render :partial => "sidebar"

Where to start:

  1. Getting Started Tutorial

  2. Html2haml converter

3488 questions
158
votes
5 answers

Append class if condition is true in Haml

If post.published? .post / Post stuff Otherwise .post.gray / Post stuff I've implemented this with rails helper and it seems ugly. = content_tag :div, :class => "post" + (" gray" unless post.published?).to_s do / Post stuff Second…
Simon Perepelitsa
  • 19,436
  • 8
  • 53
  • 72
123
votes
4 answers

How do I include inline JavaScript in Haml?

How can I write something like this to include in a template, but in Haml?
Fuego DeBassi
  • 2,781
  • 6
  • 25
  • 34
106
votes
5 answers

erb, haml or slim: which one do you suggest? And why?

I am learning Rails and I have seen these template engines. I have no experience with them (only erb). But as I am a beginner, I am really confused. Which one do you suggest and why? Erb, Haml or Slim? Please tell your reason for preferring one over…
Omid Kamangar
  • 5,580
  • 9
  • 35
  • 67
98
votes
13 answers

Haml: Control whitespace around text

In my Rails template, I'd like to accomplish final HTML to this effect using HAML: I will first link somewhere, then render this half of the sentence if a condition is met The template that comes close: I will…
Matchu
  • 77,193
  • 15
  • 148
  • 158
84
votes
5 answers

How to write if-condition in Haml?

How to write if and if-else statements in Haml for a Ruby on Rails application?
Thillai Narayanan
  • 4,500
  • 4
  • 28
  • 36
77
votes
10 answers

How do I get Haml to work with Rails?

I am trying to get Haml to work with my Ruby on Rails project. I am new to Ruby on Rails and I really like it. However, when I attempt to add an aplication.html.haml or index.html.haml for a view, I just receive errors. I am using NetBeans as my…
24hourCoder
76
votes
2 answers

How do I make dynamic ids in Haml?

#item creates a div with id="item" .box#item creates a div with class="box" and id="item" .box#="item "+x creates a div with class="box" and a comment '#="item"+x' .box# ="item"+x throws "Illegal element: classes and ids must have values." How…
user225643
  • 3,241
  • 5
  • 24
  • 22
73
votes
18 answers

incompatible character encodings: ASCII-8BIT and UTF-8

I use Ruby 1.9.2 and Rails 3.0.5 I have the following error: incompatible character encodings: ASCII-8BIT and UTF-8 It has nothing to do with the database i think. The error is happinging on this line in a view (just a div haml…
Michael Koper
  • 8,866
  • 6
  • 40
  • 56
72
votes
12 answers

Is there a HAML implementation for use with Python and Django

I happened to stumble across HAML, an interesting and beautiful way to mark up contents and write templates for HTML. Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some…
Ber
  • 34,859
  • 15
  • 60
  • 79
64
votes
5 answers

Is there a good HAML -> ERB/HTML converter?

I'm looking for a reliable way to convert a HAML template to an equivalent ERB/HTML template? Has anyone come across one?
Karlas Furecz
61
votes
5 answers

How to set inline style for element in HAML

Here is my code:
..
It parses only style='position: absolute', and doesn't parse the other styles. How can I achieve this?
ValeriiVasin
  • 8,240
  • 11
  • 53
  • 75
61
votes
1 answer

How do I make an image link tag using haml in Rails?

I have something like this in application.html.haml: #header = image_tag("header.jpg") How do I make that link to www.google.com, for example? Thanks
Tony
  • 17,359
  • 29
  • 118
  • 188
58
votes
2 answers

Ruby methods within Javascript within HAML

I have a jQuery script that adds a new field to a form, and this field contains dynamic information from an array. The problem is that I can't figure out how to add an array.each to populate the options of the select field within the javascript…
Josh
  • 603
  • 1
  • 5
  • 6
58
votes
4 answers

Best way to handle data attributes in Slim

I was evaluating Slim as a replacement for HAML in a personal project, and it doesn't appear to handle HTML5 data attributes as gracefully as HAML. I was hoping someone may have also run into this, or may have known about an option/syntax I haven't…
mmoss
  • 683
  • 1
  • 5
  • 5
57
votes
2 answers

Injecting variable values into javascript and HAML in RoR

I have the following function for using ZenDesk. I'd like to inject my current_user details into the form as follows. (this is my from html.haml template). However I cannot figure out how to make this work. :javascript if (typeof(Zenbox) !==…
Dave G
  • 4,306
  • 4
  • 22
  • 27
1
2 3
99 100