13

My inline style looks like:

style="background-image: url({{ asset('bundles/testblog/images/id.jpg') }});"

the part id of the url must change depending on a varibale. How can I make this happen inside the asset.

I tried :

style="background-image: url({{ asset('bundles/testblog/images/'{{variable}}'.jpg') }});" 

But to no avail.

madhead
  • 31,729
  • 16
  • 153
  • 201
Adib Aroui
  • 4,981
  • 5
  • 42
  • 94

2 Answers2

56

Use ~ for concatenation,

style="background-image: url({{ asset('bundles/testblog/images/' ~ variable ~ '.jpg') }});"

Also,

You don’t need to nest {{ ... }} delimiters. The ones you used to wrap asset() call are also used to print any other variable they contain.

Ahmed Siouani
  • 13,701
  • 12
  • 61
  • 72
6
style="background-image: url({{ asset('bundles/testblog/images/' ~ variable ~ '.jpg') }});" 
nni6
  • 990
  • 6
  • 13