XF 2.2 Asset Uploader

Ozzy47

Well-known member
Okay, so I'm trying something out. I created a folder in assets called "OzzModzAttachIcon" I have created a style property and have it working to store images uploaded to the created folder.

Currently in my addon, I get images like this, <img src="{$xf.options.boardUrl}/styles/OzzModz/AttachmentIcons/attach-icon/zip-itd-icon.png" alt="{$attachment.filename}" />

What I'd like to do is get the images from the asset folder and style property I created, so something like this, <img src="{{ base_url(property('myPropertyName')) }}" alt="{$attachment.filename}" />

Is it even possible?

Screenshot (489).webp
 
Thanks for the reply.

I thought it should work as well, but it outputs this, <img src="/" alt="OzzModz-NewPostsNodeWhitelist-2.0.0.zip"> when I am expecting <img alt="OzzModz-NewPostsNodeWhitelist-2.0.0.zip" src="https://mysite.com/data/assets/OzzModzAttachIcon/zip-itd-icon.png">

Template code looks like this, <img src="{{ base_url(property('myPropertyName')) }}" alt="{$attachment.filename}" />

The image is in the folder, and if I use the inspector and link to it directly, it shows as expected.
 
Hmm, it returns ""

I bet this is because I'm adding this code in attachment_macros and expecting it to show when viewing a thread?
 
Probably not, if you're getting an empty string then the property does not have a value in the style you are viewing it in.
 
Holy moley!! All this time I was uploading the image in the asset uploader, and assuming it saved automatically. I wasn't hitting "Save"
 
I'd also note that assets aren't bundled with the add-on and are more designed for admin customization, so you'd typically still ship a default image/value from the styles/ directory.
 
You could but the styles/ directory might be more appropriate. The data/ directory is more for programmatically-created files and may be mounted elsewhere on a per-installation basis.
 
I'm not sure how to use the asset uploader that way. Currently in the "Value formatting parameters" field I enter asset=OzzModzAttachIcon what would I use to get it to store the images in styles/OzzModz/AttachmentIcon
 
You wouldn't store them there, you would just set the default value (in the master style) manually to styles/something/image.png.
 
But then if a user wishes to change the image, it wouldn't upload them to my directory.
It would.

It's still just a style property that can take any URL / string.

The only difference to a "plain" style property is that it allows the user to upload images to the defined asset directory.
 
I understand that, I'm trying to make uploading images and saving the path simple for the users, as there are 50 of them.
 
That’s what the asset uploader does. It will store them in the sub-directory you specify and set the appropriate value.
 
Whatever you want (it's fine as it is). Consider the default style property publicLogoUrl. The default value is styles/default/xenforo/xenforo-logo.png, corresponding to an image in the style directory bundled with the software. The asset configuration is asset=logo, so when end-users use the asset system it is stored in data/assets/logo/some-logo.png and set accordingly.

Bundling a default image from the styles directory and using the asset system are not related to each other.
 
Whatever you want (it's fine as it is). Consider the default style property publicLogoUrl. The default value is styles/default/xenforo/xenforo-logo.png, corresponding to an image in the style directory bundled with the software. The asset configuration is asset=logo, so when end-users use the asset system it is stored in data/assets/logo/some-logo.png and set accordingly.

Bundling a default image from the styles directory and using the asset system are not related to each other.

Is there a way to specify a subdirectory (e.g. data/assets/logo/header/)?

Setting asset=logo/header/ for Value formatting parameters throws the Asset type names may only contain A-Z, 0-9, - and _ characters. error on upload.
 
Back
Top Bottom