Jared Eitnier Jared Eitnier - 1 year ago 115
Less Question

PHP pass variable to LESS CSS or identify current environment in LESS

In my LESS CSS file I define a base-url:

@base-url: 'http://cdn.domain.com';

I now have the need to dynamically switch the base url depending on what environment I am on. Ex:

DEV: 'http://domain.com'
PROD: 'http://cdn.domain.com'

Is there a way to check this directly via LESS or is there a way to pass this variable from PHP to LESS?

Answer Source

You can create two files, one for development, one for production, and compile whichever you need:

/* Production: production.less */
@base-url: 'http://cdn.domain.com';
@import "main.less"

/* Development: dev.less */
@base-url: 'http://dev.domain.com/files';
@import "main.less";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download