Calling images with a script : please help my colleague

Hello I have a colleague at École Polytechnique de Montréal who would like to call a static script from the files library, which calls static images but it doesn’t seem to work. Can anyone point us to the right documentation or experimentation results?


I would like to know if there is an equivalent to “/static/myimage.jpg” to call dynamically from a javascript script a file in the file bank of a course site on EDUlib.

Writing <img src="/static/myimage.jpg"> in an html block will work.
Writing <script src="/static/myscript.js"> will also work but if the code in myscript.js tries to call “xyz.setAttribute(‘poster’, ‘/static/myimage.jpg’)” it does not work, the link is not formed correctly. I’m looking for a way to solve this without having to rebuild the url with regular expressions or absolute links but I don’t know how to do it. Do you know if open edx has foreseen this kind of use case?


I’m the colleague. I was able to reconstruct a working link like so:

var self = regEx = new RegExp('^\/courses\/([^\/]+)\/courseware\/([^\/]+)', 'i'),
                url = window.location.pathname,
                image = 'myimage.jpg',

result = regEx.exec(url);
if (result) {
    course = result[1];
    id = result[2];
    if ( !== -1) {
        imgUrl = '/assets/courseware/v1/' + id + '/' +
            course.replace('course', 'asset') + '+type@asset+block/' + image;

It’s working in my tests but does anybody foresee potential problems?

1 Like