rendering image in Backbone JST template

291 Views Asked by At

I have images stored in my app/assets/images directory, and from my JST templates (rendered by my Backbone view) I am trying to figure out how to get the image asset path. src='assets/images/image.png' does not work. Any ideas?

Thanks

2

There are 2 best solutions below

0
Jayem On BEST ANSWER

Are you using rails as your backend? Then in your template file it should be:

<img src="/assets/image">

The path to retrieve assets starts with /

2
Alex Fatyeev On

You can try this:

var imgPath = 'app/assets/images/',
img = 'image.png',
tpl = _.template('<img src="<%- src %>">');

console.debug(tpl({ src:imgPath+img }));