Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haml formatting

I'm new to haml, so I'm still trying to figure out the formatting.

I have an index.haml file with the following code.

%h1
  Welcome to Solidarity

Hello,
= @profile.first_name
!

It renders like this:

Welcome to Solidarity
Hello, user !

Here's the page source:

<h1>
  Welcome to Solidarity
</h1>
Hello,
frances
!

It has a space between @profile.first_name and the exclamation mark. Why is that? And, how do I fix it?

like image 320
user5243421 Avatar asked Dec 29 '22 18:12

user5243421


1 Answers

%h1 Welcome to Solidarity
Hello, #{@profile.first_name}!
Please #{link_to 'post a comment', new_comment_path}!

becomes

<h1>Welcome to Solidarity</h1>
Hello, John!
Please <a href="/comments/new">post a comment</a>!

Please keep in mind that in Rails 2 and Haml 2, you must properly html-escape anything you send to the browser (ht nex3):

Hello, #{h @profile.first_name}!

In Rails 3 and Haml 3, everything is escaped by default, so you can simply do:

Hello, #{@profile.first_name}!
like image 70
yfeldblum Avatar answered Jan 10 '23 07:01

yfeldblum