Image path in JavaScript?

Image path in JavaScript?

by Kevin Burton -
Number of replies: 1

I Moodle I can associate an image with PHP something like:

$OUTPUT->pix_url('t/backup')

Which on my machine turns into 'http://localhost/moodle26/theme/image.php/standard/core/1395409220/t/backup'.

If I wanted to get the same path from JavaScript is there a utility method in the 'M' namespace that I can use or should I just copy the images to a known location and use a hardcoded value for the path?

Average of ratings: -
In reply to Kevin Burton

Re: Image path in JavaScript?

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Kevin,

See lib/javascript-static.js - there's a function called M.util.image_url which you can use.
There's also M.util.get_string() for getting language strings.

Hope this elps,

Andrew

Average of ratings: Useful (1)