Ruby code embedded in Haml?

Hi:

Isit possible to embed ruby code in Haml templates. True, using
variables seems to work fine. However, even a simple for loop
generates errors. Other members have made suggestions, but none of
them have worked. Below is a simple Haml template. When it is used in
conjunction witha a Haml layout, an Html page is displayed. Four
indexes of an array are displayed. How could a for loop accomplish the
same thing? Thank you much.

cz

#contentID
%h3 Haml Template
%p All work and no play makes Jack a dull boy.
.divbtm
%p #{@ary.at(0)}
%p #{@ary.at(1)}
%p #{@ary.at(2)}
%p #{@ary.at(3)}

On Sat, Feb 19, 2011 at 3:30 AM, cz [email protected] wrote:

cz

Dashes are for zero-width ruby, such as control characters, and equal
signs
will embed Ruby, ie interpolation.

  • @ary.each do |element|
    %p= element

Josh C. wrote in post #982617:

Dashes are for zero-width ruby, such as control characters, and equal
signs
will embed Ruby, ie interpolation.

Or perhaps more clearly: a dash is for ruby code where you don’t want
the result value inserted into the page, and equals is for ruby code
where the value of the expression is inserted into the page.

  • @ary.each do |element|
    %p= element

To be clear, this is a shorthand in haml for

  • @ary.each do |element|
    %p
    = element