roborourke / wp-less

Provides a LESS compiler compatible with wp_enqueue_style() for rapid CSS development in themes and plugins.
MIT License
217 stars 55 forks source link

setting variables from PHP - URLS not getting through #16

Closed cheekyboots closed 12 years ago

cheekyboots commented 12 years ago

I am trying to set LESS variables from PHP using the example provided.

This works: $vars[ 'foo' ] = "red";

This doesn't - the only thing that comes through is the string "http": $vars[ 'headerImg' ] = "http://mysite.dev/wp-content/themes/blah/images/blah.png";

Any ideas?

roborourke commented 12 years ago

Hi, Yeah you have to escape special strings like URLs in the less way. Set your string literal variables like this:

$vars['myvar'] = '~"http://example.com"';

roborourke commented 12 years ago

Did this work for you?

cheekyboots commented 12 years ago

Yes it did! Thank you so much. I really appreciate you getting back to me so fast.

lkraav commented 10 years ago

I think I'm having a related issue. I can't generate a value in "less_vars" filter that would match isurl() guard. Mixin is pretty simple:

.background (@url) when (isurl(@url)) {
    background: url(@url) no-repeat center top;
}

But no "url(something)" string generated in PHP (quoted, unquoted, using ~, I've tried all) wants to match that guard. Actually, I wasn't even able to succeed passing url(something) directly from within my LESS, skipping PHP altogether. Maybe a lessphp bug?

So right now what I'm doing is using isstring(@url) guard instead, and setting a default value of "false" in PHP. That works. But I'd like to know what's happening with isurl().