HAML: %li{:class => 'current' if page == 2} does not work?

Hi all

I’m iterating over navigation page links using HAML. I want to assign
the current page’s link the CSS class .current trying to use:

%li{:class => ‘current’ if params[:page] == i}

Sadly this doesn’t work. How can I achieve the wanted result?

Thanks for help,
Josh

On Feb 17, 2008, at 11:05 AM, Joshua M. wrote:

%li{:class => ‘current’ if params[:page] == i}

params are always returned as strings. Use params[:page].to_i == i or
params[:page] == i.to_s. See if that works.

I use this line in HAML, and that works fine.

%li{:class => (“active” if item[:item] == active_menu_item)}

so maybe it’s the ( ) that do the trick?

On Feb 18, 10:56 am, Joshua M. [email protected]

Steve R. wrote:

On Feb 17, 2008, at 11:05 AM, Joshua M. wrote:

%li{:class => ‘current’ if params[:page] == i}

params are always returned as strings. Use params[:page].to_i == i or
params[:page] == i.to_s. See if that works.

Thanks, but I guess I wasn’t specific enough. :wink:

My problem is that HAML throws an error when having an “if” statement
within %li{…}. Isn’t it allowed to use them?

Peter wrote:

I use this line in HAML, and that works fine.

%li{:class => (“active” if item[:item] == active_menu_item)}

so maybe it’s the ( ) that do the trick?

On Feb 18, 10:56 am, Joshua M. [email protected]

Yes, this seemed to be the problem. Thanks.