将动态变量发送到SASS [英] Sending dynamic variables to SASS

查看:244
本文介绍了将动态变量发送到SASS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在一个新项目中工作,允许用户根据自己喜欢的内容更改网站的外观。他们可以改变背景颜色和东西,它们被保存在数据库中供以后使用,或者它们可以存储在cookie中。但是我一直在使用一个php文档来模拟样式表,这样我可以传递变量< link rel =stylesheettype =text / csshref =main.php?bgColor =#444为例。这样我可以使CSS动态,不太依赖javascript。
然而有些朋友提到使用SASS,但我不知道它是否适合我的项目,因为我不知道很多关于指南针框架。如何将动态变量传递给这个.sass或.scss文件?你只是做一个 @importphp-variables; 语句并包含一个php文件?或者你可以发送动态变量,我用php? $ b $bÚ
此外,使用php比SASS有什么好处,反之亦然?

解决方案

这里似乎缺乏理解,所以我会提供一个简短的答案和一个更长的答案。 p>

short



您无法向Sass发送动态变量。对于PHP可能有一些端口,这使它成为可能,但只使用Sass,这是不可行的。



更长



您可能需要熟悉 Sass究竟是什么以及它如何适用到您的工具包。它听起来像你使用PHP,所以我想象你会有PHP渲染出HTML模板/做DB魔术,也许一个JavaScript的JavaScript做客户端脚本,你会有CSS(平原,香草CSS)样式元素



Sass / SCSS(以下简称Sass)不会取代CSS(您不会看到< link type =



Sass通常是通过编译的方式来编译的,到CSS 之前将资产发送到生产,它不会在用户请求时生成。您的Sass文件和HTML文档之间没有真正的连接,因此您将无法将任何变量传递到Sass文件。


I am currently working in a new project that allows users to change the appearance of the website base on their likes. They could change background colors and stuff, which get saved on a database for later use or they could be stored in a cookie. However I've been using a php document to emulate a stylesheet so that way I could pass variables like <link rel="stylesheet" type="text/css" href="main.php?bgColor=#444" as an example. This way I could just make the css dynamic and not rely too much on javascript.
However some friend mentioned using SASS, but I don't really know if it is suited for my project since I don't know much about the compass framework. How would you pass dynamic variables to this .sass or .scss file? Do you just do an @import "php-variables"; statement and include a php file? or can you send dynamic variables as I did with php?
And also, what are the benefits of using php over SASS, or vice-versa?

解决方案

There seems to be a fundamental lack of understanding here so I'll provide a short answer and a longer one.

short

You can not send dynamic variables to Sass. There may be some port of it for PHP that makes it possible but using just Sass, this isn't feasible.

longer

You may want to familiarize yourself with what exactly Sass is and how it fits in to your toolkit. It sounds like you're using PHP so I imagine you'd have PHP rendering out HTML templates/doing DB magic, maybe a dash of JavaScript to do client side scripting, and you'll have CSS (plain, vanilla CSS) styling elements on your site.

Sass/SCSS (hereafter, Sass) does not replace CSS (you won't ever see <link type="text/sass">), it simply provides a different syntax for writing styles that is later compiled into CSS.

Sass is typically compiled to CSS before you send your assets to production, it's not generated when a user requests it. There's no real connection between your Sass files and your HTML document so you would not be able to pass any variables to your Sass files.

这篇关于将动态变量发送到SASS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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