conditional logic in HAML

N

Noel Kelly

In the Haml tutorial has this sample:

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"

I want to convert a similar block that includes a conditional, but can't
find/google how to do it. Is it possible?

ERB

<% if ENV["RACK_ENV"] == "production" %>
<%= render :partial => "ga" %>
<% else
<div class="dev dummy">
Google Analytics in prod
</div>
<% end %>

Haml

???


Any help would be much appreciated.
 
A

Andrew Timberlake

In the Haml tutorial has this sample:

ERB

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

Haml

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

I want to convert a similar block that includes a conditional, but can't
find/google how to do it. Is it possible?

ERB

<% if ENV["RACK_ENV"] =3D=3D "production" %>
=A0<%=3D render :partial =3D> "ga" %>
<% else
=A0<div class=3D"dev dummy">
=A0 =A0Google Analytics in prod
=A0</div>
<% end %>

Haml

-if ENV["RACK_ENV"] =3D=3D "production"
=3Drender :partial =3D> "ga"
-else
.dev.dummy Google Analytics in prod


Andrew Timberlake
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top