简体   繁体   中英

How do I insert a meteor template that contains double quotes in a place where those double quotes are needed?

In my meteor web app I am trying to change the background of a certain element conditionally with this code:

.popular-games{
  background-image: url({{background}});
}

{{background}} being the path it should follow to find the image. This will not work though because the url path needs quotes, and when I put in quotes in negates {{background}}. I've tried putting the quotes into the source where {{background}} is coming from with this code:

background: "\"images/gameArt/fallout4.jpg\""

trying to add in the quotes, but this still does not work for some reason. Any help would be great.

You need to have the style in your html like this:

<div style="background-image: url('{{imagePath}}');"></div>

If the file path you return is correct, it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM