Images publish in assets folder according to JS/CSS is called or not.

Dear guys,

I have a JS (javascript) package that rely on jQuery or in other word, it’s jQuery plugin.

Then I use CClientScript to help me register this plugin. This part works successfully.

But my plugin has a CCS script which call some image files. I need them (JS files, CSS files and image files) to be publish into assets folder at the same place.

As I mention above I config clientScript packages using CClientScript so my JS files and CSS files are published into the same folder but how do I do with my image files. I can publish it using AssetManager but this will make image files go to different assets folder. So then CSS files can’t see the image files.

There is a workaround that I can think of is publishing all JS, CSS, and image files using AssetManager but my JS depends on jQuery so if I’m doing this way, Yii will mess up how they will call (I meant to include it in <header>) jQuery before call this JS plugin. And make the JS fails to run.

Basically, I’d like to let Yii publish images files like we specify the JS,CSS files in clientScript configuration.

Hope you guy get what I want, a little help will be very appreciate.

You can use absolute path in CSS file. There’s no need to add images to assets directory.

surely you can put all js , css image dir under your own assets dir:

assets

  ....    |-----  css


  ....    |-----  js


  ....    |-----  images

use assetsManager publish whole assets dir to assets dir of webroot :

…|- webRoot

… |–assets

… |----- xxxxx(hashed dirName)

… |----- css

… |----- js

… |----- images

after you publish your assets dir , you can get the baseUrl of your assets lets call it baseUrl .see(publish method detail)

then you use clientScript to registCoreScript(‘jquery’), registerScriptFile(‘yourJqueryPlugin’),

in the css file which refer to some resource files of images ,because the relative path is still the same with your original assets. so all is going well :D