Path to image in JS scripts published via assetsManager

Hi there,

Again, this seems to be horribly simple, but I can’t figure it out.

I have file called mytooltip.js, placed in protected/scripts/mytooltip/ and published via:

//Include tooltip script

$assets = Yii:app()->basePath.'/scripts/mytooltip';

$url = Yii::app()->getAssetManager()->publish($assets);



Inside mytooltip.js I have such piece of code:

var mySettings=


	userTooltipOffset: [11, 11], //Additional x/y margin between objectand mouse cursor.

	loadingHTML: '<div><img src="mytooltip.gif" width="30" height="30" alt="Loading">Loading...</div>',


How can I set/change path to image in img tag inside this script after it’s publication? How can I make it visible by passing valid path in any possible way?

Using this JS script was piece of cake when including in static HTML page. All files (mytooltip.html, mytooltip.js, mytooltip.css and mytooltip.gif) were in the same folder, so there was no need to pass any path.

But after moving this script to Yii and assetsManager approach, this became real pain in the ass (at least for me).



refer to Send asset folder path to a javascript of a widget

i think you should pass the assetsUrl to this code :

‘<div><img src=“mytooltip.gif” width=“30” height=“30” alt=“Loading”>Loading…</div>’,

it is just pure string , in js you can use “+” to concate :)

and this code :

$assets = Yii:app()->basePath.’/scripts/mytooltip’; not good; because the “/” may cause some problem in different os(you see windows or *nix )

why not use the pathAlias "webroot.scripts.mytooltip"

Note that publish() can publis an entire folder ;)

This way you can have all in one folder or the pictures in the subfolder of the script folder (in that case you use the relative path in your script)… and they will be published together - not in separate assets

Thanks both of you. Both your solutions are great and so simple, that I’m beating myself, that I haven’t figured it out myself! :expressionless: