Jared Eitnier
Jared Eitnier

Reputation: 7152

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?

Upvotes: 4

Views: 1852

Answers (2)

Rob W
Rob W

Reputation: 349052

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

Upvotes: 7

Vinícius Moraes
Vinícius Moraes

Reputation: 3516

Here is a way to parse php variable to less files.

http://leafo.net/lessphp/docs/#setting_variables_from_php

Upvotes: 1

Related Questions