Pass a variable to sass from programming language (coldfusion or PHP)

爷,独闯天下 提交于 2019-12-08 13:46:42

问题


I would like to pass a variable to my sass from coldfusion or php.

Above I declare a var that I need to pass to sass to set a container-size in my _base.sass.

Is there a way to do it?


回答1:


Use the !default flag in your variable to do this. here's what i mean

// SCSS file
@import "php-variables"; // have php write this file first before compiling
@import "variables"; // custom colors, font-sizes, etc.

// contents of php-variables

$myvar: #f00; // the value you're setting with php

// contents of variables

$myvar: #0f0 !default; // the value to use if php DOESN't override it.

This way you can still have a fallback for if your php code doesn't need to override a var. anything you write in the php file will be declared first. then as long as your variables file uses the !default flag on ALL variables then it won't override the php set ones.

more info here:

http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#variable_defaults_

I have tested this with the php compiler at http://www.phpsass.com/ and it works.




回答2:


I think you should be writing directly to the sass file through php/coldfusion. I doubt there is another way to do it.

An easy way to do this would just be to put your variable on your first line in the sass file or something and just overwrite the value using PHP.



来源:https://stackoverflow.com/questions/8985109/pass-a-variable-to-sass-from-programming-language-coldfusion-or-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!