将变量从编程语言(Coldfusion或PHP)传递给sass [英] Pass a variable to sass from programming language (coldfusion or PHP)

查看:75
本文介绍了将变量从编程语言(Coldfusion或PHP)传递给sass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Coldfusion或php将变量传递给我的Sass.

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

上面我声明了一个变量,该变量需要传递给sass以便在_base.sass中设置容器大小.

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

有办法吗?

推荐答案

在变量中使用!default标志来执行此操作.这就是我的意思

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.

这样,如果您的php代码不需要覆盖var,您仍然可以使用一个备用.您在php文件中编写的所有内容都将首先声明.那么只要您的变量文件对所有变量都使用!default标志,就不会覆盖php设置的变量.

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.

更多信息在这里:

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

我已经在 http://www.phpsass.com/上使用php编译器对其进行了测试,有效.

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

这篇关于将变量从编程语言(Coldfusion或PHP)传递给sass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆