Is there a way to load base url for background-image in css file? for example:

background-image: url('{base_url}/myimage.jpg');
background-repeat: repeat;
  • I don't think you can get base url in CSS. Why you want to keep the image in the root folder? – Kalyan Chakravarthi V Feb 27 '18 at 2:40
  • @KalyanChakravarthiV for research purpose – nortonuser Feb 27 '18 at 2:58
  • 1
    In that case you may need to write your own magento handler if CSS has special syntax for rendering base url. Or else keep that piece of CSS code in phtml file and include it somewhere in the head section. It may solve your problem. – Kalyan Chakravarthi V Feb 27 '18 at 3:19
  • no such way,use inline in your phtml file – Rahul Singh Feb 27 '18 at 5:15
  • Just a side note: Having a need of specifying the base url in a CSS file actually tells me that your image is not located at a place where it is supposed to be. Usually you would - as an example - put your CSS file somewhere at skin/frontend/theme/theme/css/ - and your images than would be in skin/frontend/theme/theme/images/. Per that structure you then would specify your background path as background-image: url('../images/myimage.jpg'). I mean to say, you're better off checking why you actually have a need for the base url (i.e. why is your image located in the webroot) and fix that. – Christoph Farnleitner Feb 27 '18 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.