Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I share variables between different imported files?

Tags:

sass

I want to use SASS in a modular way. In the code segment below you can see a way I consider organizing some of the layouts of a page.

What I have in mind is the external variables in languages like C.

// file: some_page.scss   //    // I want some variables from the fonts, colors partials   // to be visible to the buttons partial   // Is it possible?    // error: _buttons.scss (Line X: Undefined variable: "$color_blue")  @import "colors"   @import "fonts"   @import "buttons"   // in file: _colors.scss   $color_blue: blue;  // in file: _buttons.scss    .button {     background-color: $color_blue; } 
like image 896
Dimitris Zorbas Avatar asked Dec 14 '12 18:12

Dimitris Zorbas


People also ask

How do you pass variables between files in Python?

To use global variables between files in Python, we can use the global keyword to define a global variable in a module file. Then we can import the module in another module and reference the global variable directly. We import the settings and subfile modules in main.py . Then we call settings.

How do I share global variables across modules?

We can create a config file & store the entire global variable to be shared across modules or script in it. By simply importing config, the entire global variable defined it will be available for use in other modules.

Can global variable be access from another file Python?

It is impossible to globalise a variable inside a function in a separate file.


2 Answers

Yes, that's how it works.

As long as _colors.scss is imported before the other files.

You can check out the port of Twitter Bootstrap to Sass here: https://github.com/thomas-mcdonald/bootstrap-sass it uses variables in a similar fashion.

like image 132
Simon Boudrias Avatar answered Nov 23 '22 16:11

Simon Boudrias


You need to add a ; at the end of the @import line.

like image 24
Chloe Avatar answered Nov 23 '22 18:11

Chloe