1

I am trying to create a Bootstrap card with jquery. Everything is working except the "img".

This code works in the scala.html file but not in the html files:

<img src="@routes.Assets.versioned("images/friend_request.png")" width="28" height="22" />

This code doesn't work in the javascript file:

var createCard = $('<div class="col-md-4"><div class="card"><div class="card-body"><img src="@routes.Assets.versioned("images/friend_request.png")" width="28" height="22" /></div></div>')
$(".box" ).append(createCard);

I found a way to solve this problem, not sure if thats the best way tho.

This code works:

var createCard = $('<div class="col-md-4"><div class="card"><div class="card-body"><img src="/assets//images/friend_request.png" width="28" height="22" /></div></div>')
$(".box" ).append(createCard);
Silvan
  • 71
  • 7
  • It's probably not compiling the @routes.Assets.at since that seems like code in the View and not , valid html, so maybe try changing src="@routes.Assets.at(""), to src="/images/friend_request.png" in your declaration of createCard – Ryan Wilson Apr 28 '18 at 19:15
  • @Ryan Wilson this doesn't work. In Play you can access files only with the controller. – Silvan Apr 28 '18 at 19:33
  • You can not use the twirl syntax in the static js file. Please look the https://stackoverflow.com/questions/48003005/how-to-update-src-of-a-img-from-javascript-in-a-play-framework-project/48006036#48006036 – Andriy Kuba Apr 30 '18 at 08:14
  • @AndriyKuba thank you i didn't see that – Silvan May 02 '18 at 12:09

0 Answers0