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

3540 questions
37
votes
2 answers

Rendering partial with locals in Haml?

I am learning Haml. My view files are like: show.html.haml: .content = render 'meeting_info', :locals => { :info => @info } and _meeting_info.html.haml: .detail %table %caption Meeting Informations of =…
ssri
  • 1,290
  • 4
  • 15
  • 23
37
votes
3 answers

How to do data- attributes with Haml and Rails?

I can have %a{href: '#', data_toggle_description_length: 'toggle_me_ajax'} which it gives me underscores not dashes, i.e. However I want to have HTML data- attributes, i.e.
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
35
votes
3 answers

A html string is escaped in haml file

#test - html = "Test" = html The output is
<a href='http://www.a.com'>Test</a>
But I want a output: Anyone has…
garrydou
  • 353
  • 1
  • 3
  • 5
35
votes
3 answers

How to generate Haml views instead of erb

I'm building an app with Rails 2.3.4 and using script/generate controller home index to generate a controller and home page. I've got Haml installed. I get an erb file: app/views/home/index.html.erb but I'd prefer to have a Haml file generated…
Daniel Kehoe
  • 10,952
  • 6
  • 63
  • 82
33
votes
2 answers

How to remove unwanted indent from HAML's pre tag

I have problem with
, here is my code, and the screenshot is attached below. How to remove the indents? 
%pre.code
    :escaped
        
        
Cheng
  • 4,816
  • 4
  • 41
  • 44
33
votes
5 answers

What is the best way to check if an attribute exists and is set?

I have a common view that lists two different models. The only difference is that when setting the link_to action, one of the models has a link attribute and the other doesn't. I want to check if the link attribute exists, and if it does, check if…
Eric Norcross
  • 4,177
  • 4
  • 28
  • 53
33
votes
5 answers

Haml syntax: split a line to a couple of rows

I use HAML in my rails project for my html templates. I would like to figure out if its possible to divide a very long line and make it a couple of rows: %a.open-service{href: '#', data: { service_name: service.description, balance_type:…
benams
  • 4,308
  • 9
  • 32
  • 74
32
votes
1 answer

Create a local variable in Haml only

I'm using Haml as a quick way of prototyping layouts. This is not using Rails, Sinatra or any framework. What I want to do is declare a variable at the top and be able to call it throughout the page, similar to the way I can declare a variable in…
Adam
  • 4,054
  • 4
  • 25
  • 28
31
votes
6 answers

add checkbox with simple_form without association with model?

How I can add checkbox with simple_form without association with model? I want to create checkbox which will handle some javascript events, but don't know? Maybe I miss something in documentation? Want't to use similar like following: =…
Mikhail Grishko
  • 4,258
  • 3
  • 22
  • 21
31
votes
3 answers

HAML - parameter with dash

How can I convert this line to HAML syntax? This one returns me an error %body{:data-spy => "abcd"}
user984621
  • 46,344
  • 73
  • 224
  • 412
30
votes
4 answers

"[ !IE]" conditional comments in Haml

In a HAML doc, I have: /[if IE] This is IE /[if !IE] This is not IE The first conditional evaluates properly in IE (and presumably in Firefox and Chrome, as "This is IE" does not render in those browsers). However, The second conditional does…
BronzeGate
  • 504
  • 1
  • 4
  • 11
30
votes
5 answers

HAML: remove white space after "link_to"

The following code leaves a white space in HTML: = link_to "Login", "#" Normally, HAML allows to remove it by putting ">" at the end of the line, for example: %input#query{:type => "text", :value => "Search"}> However, that seems to be impossible,…
krn
  • 6,715
  • 14
  • 59
  • 82
30
votes
5 answers

How to Show Error Messages Next to Field

I have a form with input fields/labels etc. How do I get the error message to show up next to the field? instead of clumped together at the top? I am using devise, rails 3 I have this at the top of my form: = form_for(resource, :as =>…
newbie_86
  • 4,520
  • 17
  • 58
  • 89
30
votes
8 answers

Count number of selectors in a css file

is there an existing plugin/app/program/script/whatever that analyzes and counts the css selectors of a file? i want to check if the reason my css file is not working in IE is because my selector count is over 4095 (which im pretty sure is…
corroded
  • 21,406
  • 19
  • 83
  • 132
30
votes
5 answers

Contact form in ruby, sinatra, and haml

I'm new to all three, and I'm trying to write a simple contact form for a website. The code I have come up with is below, but I know there are some fundamental problems with it (due to my inexperience with sinatra). Any help at getting this…
dcb
  • 940
  • 1
  • 8
  • 12