Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a variable from PHP to LESS?

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?

like image 368
Gregory Bolkenstijn Avatar asked Nov 15 '11 12:11

Gregory Bolkenstijn


People also ask

What is the use of $$ in PHP?

What does $$ (dollar dollar or double dollar) means in PHP ? The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using the $ symbol before the $x value.

What does ?: Mean in PHP?

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.


2 Answers

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

like image 83
leafo Avatar answered Oct 13 '22 21:10

leafo


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

like image 3
bencoder Avatar answered Oct 13 '22 23:10

bencoder