Search code examples
csscompass-sass

How can I use compass inline-image helper with an image url that is not relative?


Problem

How can I use compass inline-image helper with an image url that is not relative?

config.rb

relative_assets = false

I also tried commenting that out completely

This code works

hdr-main.png lives in the /test/images/ on my local Server.

.test{
$image:"hdr-main.png";
background: inline-image($image);
}

This code does not work

.test{
$image:"http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/hdr-main.png";
background: inline-image($image);
}

Displays this error

Compass was unable to compile one or more files in the project:
File not found or cannot be read: /Users/myname/test/images/http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/hdr-main.png

Solution

  • I'm not entirely sure what the issue is since you haven't actually asked a question. You have working code and I'm assuming you're trying to render a production stylesheet as well.

    You should probably leave $image: "hdr-main.png" as-is then use config.rb to set your http_images_path to http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/.

    You'll want to probably use this in conjunction with setting the environment to production.

    if environment == :production
      http_images_path = "http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/"
    end
    

    then you'd build your CSS with the following

    compass compile -e production

    Again, this is assumption since there isn't a clear question posted above. If this isn't what you need, please ask a specific question.