0

I'm building a a module and I am having trouble trying to load images for my css styles and views..

is there a way to do this?

file stucture: third_party:

  • module
    • javascript
    • css
    • views

I have tried '../images/file.png' but no go as obviously the path is incorrect on page render.

2

You'll need to use the themes folder to use assets like images. So use a file structure like this:

/system/expressionengine/system/third_party/my_addon/[your-addon-files]
/system/expressionengine/system/third_party/my_addon/views/[your-addon-view-files]
/themes/third_party/my_addon/css/[css-files]
/themes/third_party/my_addon/images/[your-images]
/themes/third_party/my_addon/javascript/[your-js]

Then you can use ../images/my-image.png in your css files.

Use ee()->cp->add_to_head() to add the CSS to the CP's head-element.

Use ee()->cp->add_to_foot() to add any JS to the footer of the CP.

See also:

| improve this answer | |
  • i was afraid that would be the answer.. will have to create an installer for the module then.. oh well. – 4razmus Jun 14 '13 at 11:41
  • also you can use: ee()->cp->load_package_css('main'); and ee()->cp->load_package_js('jquery-1.10.1.min'); to load css/js into the cp – 4razmus Jun 14 '13 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.