Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less/sass with php

Tags:

I am a front end developer and have recently considered using SASS or LESS for CSS development.

However I do not use Ruby and I don't want to rely on users having JavaScript active. Does anyone have any tips for using SASS or LESS using PHP projects?

like image 655
Adi Avatar asked Feb 13 '11 19:02

Adi


People also ask

Can you use Sass with PHP?

The problem with using Sass is that it doesn't integrate nicely with PHP-based projects. Sass is written in Ruby, so everyone on the team must have Ruby installed on their development machines and then the Sass gem installed. It isn't a huge hassle, but it falls outside the project workflow.

Is SCSS better than Sass?

SASS has more developer community and support than SCSS. SASS supports SassDoc to add documentation whereas SCSS allows inline documentation. SASS can't be used as CSS and vice-versa whereas a valid CSS code is also a valid SCSS code.

Is Sass deprecated?

As part of our ongoing initiatives, we've decided to deprecate Sass, with the aim of improving the user experience of storefronts, and paving the way for future advancements. In the short term, Sass will continue to work on Shopify themes, but we are actively migrating our themes to use only CSS stylesheets.

Is Sass better than CSS?

SCSS contains all the features of CSS and contains more features that are not present in CSS which makes it a good choice for developers to use it. SCSS is full of advanced features. SCSS offers variables, you can shorten your code by using variables. It is a great advantage over conventional CSS.


2 Answers

Download the latest version of lessphp here.

Here is an example on how I tried it:

<?php require 'lessc.inc.php';  $less = new lessc('test.less'); file_put_contents('test.less.css', $less->parse());  ?> <html> <head>     <title>Less CSS</title>     <link rel="stylesheet" href="test.less.css" type="text/css" /> </head> <body>     <h1>This isn't supposed to be black!</h1> </body> </html> 

And my test.less file:

@color : #33ddff; .colorful(@textcolor : red){     color : @textcolor; } h1{     .colorful(@color); } 

It works for me, and it's php!

like image 142
Lulu the hero Avatar answered Oct 02 '22 00:10

Lulu the hero


You now have two options written by me:

  • LESS: http://leafo.net/lessphp/
  • SCSS: http://leafo.net/scssphp/ (Only has SCSS syntax, not the indentation based SASS syntax)

Both are well documented. I encourage you to try them out and tell me if you have any trouble.

like image 45
leafo Avatar answered Oct 02 '22 01:10

leafo