Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use a variable in a url() with dynamic stylesheet loading #657

Closed
paulogaspar7 opened this issue Feb 23, 2012 · 2 comments
Closed

Comments

@paulogaspar7
Copy link
Contributor

At twitter bootstrap you have a couple of variable used to fill in url()s.

They are declared here:

and look like this:

    // Sprite icons path
    @iconSpritePath:          "../img/glyphicons-halflings.png";
    @iconWhiteSpritePath:     "../img/glyphicons-halflings-white.png";

And they are used here:

on a bit of code looking like this:

    background-image: url(@iconSpritePath);
    ...
    }
    .icon-white {
        background-image: url(@iconWhiteSpritePath);
    ...

If you dynamic load it using:
<link rel="stylesheet/less" href="assets/less/bootstrap.less">
<script src="assets/js/less-1.2.2.js"></script>

... with less 1.2.2 you get:

Cannot call method 'charAt' of undefined
in sprites.less 
at Object. (http://localhost:8000/assets/js/less-1.2.2.js:2873:47)
at Object. (http://localhost:8000/assets/js/less-1.2.2.js:766:28)
...
at Object.rule (http://localhost:8000/assets/js/less-1.2.2.js:1157:33)

...which refers to:
https://github.com/cloudhead/less.js/blob/master/dist/less-1.2.2.js#L2873

where you can find this line of code from the tree.URL() function:

   val.value = paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);

So, apparently the variable was not resolved.

Notice that it all works with "lessc"!!! It is a problem only with dynamic loading.

This was the subject of issue #623 which was closed without being solved.
(Possibly because @Anahkiasen turned to using lessc???)

Anahkiasen reported he no longer has an error when he quotes the variables, but not having an error does not means the variables are now resolved. What happens when you replace this less code:
background-image: url(@iconSpritePath);

...by the quoted variant which Anahkiasen mentions on

...is this:
background-image: url("@iconSpritePath");

...is that you simply get this CSS output:
background-image: url("@iconSpritePath");

So, no error but no proper variable resolution either since Less just interprets the quoted variant as a literal instead of as a variable.

@lukeapage
Copy link
Member

Think this is fixed in the latest trunk? Anyway you can retry?

@lukeapage
Copy link
Member

cannot reproduce any longer - just tested your example :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants