2

I'm trying to compile LESS from PHP and don't want to use node.js or ruby.

There's this PHP implementation I found through Google but it seams really outdated and lacks support for newer features.

I was thinking of using the V8js API to run less.js, would that work since it has no DOM support?

Basically my question is: How can I run this JS file from a PHP application?

7
  • 3
    exec('lesscss foo.less') :-) Nothing forbids you from executing less from PHP :) Commented Sep 18, 2011 at 17:37
  • 2
    Also, why are you compiling it at runtime? Should you just compile it pre-deployment? Commented Sep 18, 2011 at 18:18
  • @arnaud576875: that would be the ruby approach I don't want to use, wouldn't it? Commented Sep 18, 2011 at 19:44
  • 1
    @JohnD: Because it's a lot of less files and each of my views uses a different combination of them. I have to compile and cache on the fly. Commented Sep 18, 2011 at 19:44
  • 1
    @Tom, it would, and looks perfectly fine. I think less is smart enough to re-compile only the files you modified, so you can easily compile them in real time during dev. (At least I do that with SASS/SCSS, and I have the same many-files approach.) Commented Sep 18, 2011 at 19:53

4 Answers 4

5

Here's the answer:

https://github.com/leafo/lessphp

There's no other way for the moment.

Sign up to request clarification or add additional context in comments.

3 Comments

A run through on getting LESSPHP working completely autonomously (compile, cache and serve - and you just need to reference your LESS file in your HTML as you would CSS): stackoverflow.com/questions/12274628/compile-less-css-with-php
this doesn't perform too well on large amounts of less
There's another less compiler available now: github.com/oyejorge/less.php
1

If you want completely hands-free LESS compiling, try Relayer:

http://relayer.co

It's free and very simple to use.

Comments

1

You can use PhpLessDemandBridge for that

You can simply use it in your Templates, like:

<link rel="stylesheet" type="text/css" media="all" href="css/engine/css.php?file=bootstrap.less" />

The Engine can be configured via config file, where you define your path to the less files and cache files.

By defining "css.php?file=bootstrap.less", you point the Engine to the bootstrap file, which imports other less files e.g. Twitter Bootstrap or such.

I am using this for Magento, TYPO3 CMS and many more.

In the first line, i am including needed parts of Twitter Bootstrap - after that i am including my own theme and overrides.

1 Comment

this is just a wrapper for the previously mentioned lessc.
0

Good news! We have new Less compiler for this case: https://github.com/wikimedia/less.php

It has no namespace issues and is easy enough to add and use.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.