How to pass a variable from PHP to LESS?

2019-02-13 08:27发布

问题:

I use PHP (lessphp) to compile LESS files into CSS files on the serverside. I would like to pass a variable to the LESS file, like a color or a language:

compile('input.less?lang=en')

and use it as a variable in LESS like @lang.

Is this possible? If not, are there any workarounds?

回答1:

This is a built in feature of lessphp, here's the documentation: http://leafo.net/lessphp/docs/#setting_variables_from_php



回答2:

I don't know less or lessphp so this may not be helpful and you may have already looked at it, but on the site I notice someone else has asked the same question and there are a couple of responses:

http://leafo.net/lessphp/#dsq-comment-132897969 (You'll have to wait for it to load the comments from disqus)

It looks like Nico-B has developed a patch to do this: https://github.com/Nico-B/lessphp/commit/aacc195fff4ec0075226a29bc832de371a8001ce#diff-1