Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

css

php

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?

like image 400
Jared Eitnier Avatar asked Feb 16 '23 12:02

Jared Eitnier


2 Answers

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";
like image 114
Rob W Avatar answered Feb 23 '23 00:02

Rob W


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

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

like image 41
Vinícius Moraes Avatar answered Feb 22 '23 23:02

Vinícius Moraes