Jared Eitnier Jared Eitnier - 4 months ago 24
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?


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";