简体   繁体   English

如何将变量从一个lesscss样式表传递到包含的样式表?

[英]How to pass variables from one lesscss stylesheet to an included stylesheet?

I am attempting to use lesscss to build a templating system where each template has 3 or 4 alternative colour schemes. 我试图使用lesscss来构建模板系统,其中每个模板有3或4个替代配色方案。

So for example, I could have a red.less stylesheet that looks like this: 例如,我可以有一个看起来像这样的red.less样式表:

@main_colour: #ff0000;
@import 'main.less';

So, I only have one main.less stylesheet to maintain which contains all the main styles, and uses the variables set for colour codes. 所以,我只有一个main.less样式表来维护,其中包含所有主要样式,并使用为颜色代码设置的变量。 I can then create a seperate colour.less file for each colour scheme. 然后,我可以为每个配色方案创建一个单独的colour.less文件。

Only problem is when I try to do this I get a Less::VariableNameError which indicates that LESS is parsing the @imports BEFORE it parses the variables. 唯一的问题是,当我尝试这样做时,我得到一个Less::VariableNameError ,它指示LESS在解析变量之前正在解析@imports。

Is there a workaround to this or any other way to achieve the same end result? 是否有解决方法以此方法或任何其他方式来实现相同的最终结果?

In reference to your tweet , yes, this would work as you expect in Sass . 关于你的推文 ,是的,这可以像你在Sass中所期望的那样工作。 I'm actually kind of surprised that it doesn't work in Less. 我真的很惊讶它在Less中不起作用。

I guess the Less guys wanted to keep the .Less file atomic and independent of external environmental settings. 我想Less的人希望保持.Less文件的原子性和独立于外部环境设置。 This was what I assumed, but I also didn't like it so our .NET port http://www.dotlesscss.com will allow you to do this by default. 这就是我的假设,但我也不喜欢它,因此我们的.NET端口http://www.dotlesscss.com将允许您默认执行此操作。

Its not a big change to do in the original Less ruby version and if you fancy tinkering with the source I can point you in the right direction. 它在原版Less ruby​​版本中不是一个很大的变化,如果你喜欢修改源代码,我可以指出你正确的方向。

Out of interest, without been traitorous to the Less team I quite like the SASS syntax now and there are additional things such as conditional statements and loops that you cant (yet) do with Less. 出于兴趣,没有参加Less团队,我现在非常喜欢SASS语法,还有一些其他的东西,比如你不能用Less做的条件语句和循环。

@nex3 - you guys should stop competing and just work together. @ nex3 - 你们应该停止竞争,只是一起工作。

使用最新的LESS似乎现在工作正常。

似乎这不再是一个问题,或者至少不是我使用“dotless”for .net?

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

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