32

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 Sass and use it throughout the code.

!!! 5
  %body
    / Declare Variable
    - $type = 'Audio'

    .container{:id => "page-#{$type}"}

Is this possible?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Adam
  • 4,054
  • 4
  • 25
  • 28
  • 5
    Prefixing a variable with `$` in ruby defines it as global, which is probably not what you want. Drop the `$` and just use `type`. – Casey Foster Sep 14 '12 at 19:47
  • yeah, it was. it was a completely foolish mistake on my part. thank you guys. and thanks for the heads up about the global variable as well. – Adam Sep 14 '12 at 21:22

1 Answers1

53

Drop the $ to avoid declaring a global variable. It should work just fine.

!!! 5
  %body
    / Declare Variable
    - type = 'Audio'
    .container{:id => "page-#{type}"}
Kyle
  • 21,978
  • 2
  • 60
  • 61