XF 2.0 What's the correct way to use an image in an addon in XF2?

Yugensoft

Well-known member
Which directory do I put the image in, such that it deploys and is easily referable to in the addon, in XF2?

Currently I'm just replicating the descendant directory naming scheme as in src/addons in the style directory and adding to the additional files in build.json. Just checking that's "how it's done".

Thanks
 
Have a read of this section of the documentation: https://xenforo.com/xf2-docs/dev/development-tools/#customizing-the-build-process

Specifically the part:

If you have assets, such as JavaScript, which need to be served outside of your add-on directory, you can tell the build process to copy files or directories using the additional_files array within build.json. During development it isn't always feasible to keep files outside of your add-on directory, so if you prefer, you can keep the files in your add-on _files directory instead. When copying the additional files, we will check there first.​
You can use the same process for copying images from your addon folders to the root product folders
 
Have a read of this section of the documentation: https://xenforo.com/xf2-docs/dev/development-tools/#customizing-the-build-process

Specifically the part:

If you have assets, such as JavaScript, which need to be served outside of your add-on directory, you can tell the build process to copy files or directories using the additional_files array within build.json. During development it isn't always feasible to keep files outside of your add-on directory, so if you prefer, you can keep the files in your add-on _files directory instead. When copying the additional files, we will check there first.​
You can use the same process for copying images from your addon folders to the root product folders
Hey @Sim
I have Earl/ThreadChooser/_files/Earl/ThreadChooser/Image.jpg and Earl/ThreadChooser/_files/Earl/ThreadChooser/clTrigger.js files.

In the templates, the javascript loads without any problem like this
<xf:js src="Earl/ThreadChooser/clTrigger.js" addon="Earl/ThreadChooser"/>

but how do I link to image.jpg file?
 
Store the files in the default js directory, and also the images whereever you need them, and include them in the build.json.

You are trying to do it vice-versa, thats the wrong direction.
 
Back
Top Bottom