How should I reference resources (like image files) in my JavaScript code? Currently I have a jQuery plugin loaded in the footer, and the required images uploaded in the themes page along with all my other site-wide resources. I'm using relative file paths, i.e., just the name. This works for everything else (like css or images used in html, but for some reason doesn't seem to work with JavaScript.
Official response from Jesse Haff
First, upload your image files to the Theme > Files page. Then you can define the images as variables in your <script> tag prior to JS file included, as such:
var my_image_1 = '{{ theme['image1.jpg'] }}';
Share this post
Showing 4 reactions
Sign in with