PHP pass a variable in LESS CSS or define the current environment in LESS

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

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

Now I need to dynamically switch the base url depending on the environment in which I am included. Example:

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

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

+4
source share
2 answers

You can create two files: one for development, one for production and compile depending on what 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"; 
+7
source

Here is a way to parse a php variable into fewer files.

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

+1
source

Source: https://habr.com/ru/post/1481774/


All Articles