Is there a way to use variables from my Ruby application inside a Sass file?
The basic syntax for defining a variable is simple: Just use a $ before the variable name and treat its definition like a CSS rule: Sass Variable Syntax: $<variable name>:<value>; The following declares a variable named large-font.
Sass variables are only available at the level of nesting where they are defined. Will the color of the text inside a <p> tag be red or green? It will be red! The other definition, $myColor: green; is inside the <h1> rule, and will only be available there!
Sass variables are all compiled away by Sass. CSS variables are included in the CSS output. CSS variables can have different values for different elements, but Sass variables only have one value at a time.
Declaration of a variable in SASS: In SASS, you can define a variable by using $ symbol at the starting of the name of the variable and followed by its value. Understanding scope of a variable: SASS variables can be declared anywhere in the document before it is used.
You can add .erb extention to your .sass file and then add your variables just like in regular .erb file:
<%= APP_CONFIG[:yourkey] %>
More information:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With