Nistor Cristian
Nistor Cristian

Reputation: 1266

Wordpress - Less And PHP

I'm trying to figure out how to make a mixins.less file using PHP variables. I made an Admin page and inside it I have colour selector. I want to use that colour inside my less files.

@colour: $mycolour;

I'm thinking to write a din_mixinds.less file using PHP and inside it to add the text; And the to include the files in my style.less.

Or how can I do something better like this:

<?php
   header("Content-type: text/css; charset: UTF-8");

   $brandColor = "#990000";
   $linkColor = "#555555";
   $CDNURL = "http://cdn.blahblah.net";
?>

But with less not css.

Thank you

EDIT: Based on Bass Jobsen answer.

Gives me an error:

<?php
header("Content-type: text/css; charset: UTF-8");
?>
body{
    background-color: <?php echo 'red'; ?>;
}

Doesn't return any errors:

<?php
header("Content-type: text/css; charset: UTF-8");
?>
body{
    background-color: red;
}

Upvotes: 0

Views: 95

Answers (1)

Bass Jobsen
Bass Jobsen

Reputation: 49044

Well technical you can create a less.php file:

<?php
header("Content-type: text/css; charset: UTF-8");
$brandcolor = "#ff0099";
echo "@brandcolor: $brandcolor;";

And than serve that file on a URL (web server) and write in your Less code:

@import (less) url('http:/localhost/less.php');
p{
color: @brandcolor;
}

update

Yes ... I use less.php

I think that creates a different situation, with less.php you can use the following code to solve your issue:

$parser = new Less_Parser();
$parser->parseFile( 'style.less', 'http://example.com/mysite/' );
$parser->ModifyVars( array('brandcolor'=>'#ff00ff') );
$css = $parser->getCss();

Upvotes: 1

Related Questions