简体   繁体   English

将SCSS编译为CSS由于SCSS文件中的PHP变量,导致编译错误。 如何克服它?

[英]Compiling SCSS to CSS Compile error due to PHP Variables in SCSS file. How to get past it?

I have a bunch of SCSS file and I am trying to compile them to CSS. 我有一堆SCSS文件,正在尝试将它们编译为CSS。 I have tried using both Koala and Scout . 我尝试过同时使用KoalaScout

Error:
C:\Users\Ben\Desktop\officeincambridge\public_html\oc-content\themes\bender\sass\user.scss
error sass/user.scss (Line 2: Undefined variable: "$widgetbackground".)
create css/user.css

.SCSS file: .SCSS文件:

.user-card{
background-color:$widgetbackground;
position: relative;
padding-left:120px;
height:120px;
@include border-radius(4px);
margin-bottom:25px;
ul{
    padding:15px;
    margin:0;
    list-style: none;
}

I understand why the error is coming up, but how can I compile the SCSS file with PHP variables? 我知道为什么会出现错误,但是如何使用PHP变量编译SCSS文件? For further info, I am using OSCLASS 有关更多信息,我正在使用OSCLASS

Thanks 谢谢

You can't. 你不能 Sass is a Ruby tool, not PHP. Sass是Ruby工具,而不是PHP。

Edit: according the source code, $widgetbackground is defined in the colors.scss file. 编辑:根据源代码, $widgetbackground是在colors.scss文件中定义的。

You can indeed compile SCSS with PHP, please go through the following Module . 您确实可以使用PHP编译SCSS,请通过以下模块进行操作 I've used that in my project, and it works just fine. 我在项目中使用了它,效果很好。 All you have to do is, 您要做的就是

  1. Include the Module into your project 将模块包含到您的项目中

  2. Create a Style.php file. 创建一个Style.php文件。 and specify the input directory, given in their document. 并指定其文档中提供的输入目录。

  3. Pass the scss file you have under your assets directory, as an argument to style.php 传递资产目录下的scss文件作为style.php的参数

    style.php/?p=application.scss

  4. You will have the compiled file generated, under your Assets Directory, 您将在“资产目录”下生成已编译的文件,

Style.php File Style.php文件

    $scss = new scssc();
    $scss->setFormatter("scss_formatter_compressed");

    $server = new scss_server("assets/", "assets/", $scss);
    $server->serve();

Here "Assets" means the directory which contain the SCSS files, be sure about the relative path. 这里的“资产”是指包含SCSS文件的目录,请确保相对路径。

Sass is a great tool, happy coding. Sass是一个很棒的工具,编码愉快。 Hope this helps someone. 希望这对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM