What is the Gallery ImageItem "slug" property?

What is this property? What is it used for? How should it be set?

I understand what a slug is in general:
https://yoast.com/slug/

But what does it mean when it’s part of a Gallery? Is the gallery building URLs?

I need to programmatically manipulate Gallery items…

Q. What do I need to set for slug?
Q. Is slug required?
Q. What happens if you don’t set it? (ie, what functionality do you lose?)

Here are the API docs for the Wix Gallery API:
https://www.wix.com/corvid/reference/$w.Gallery.html

Specifically, ImageItem:
https://www.wix.com/corvid/reference/$w.Gallery.html#ImageItem

The documentation for slug is…less than helpful…

slug string Item slug.

The API docs for items():

https://www.wix.com/corvid/reference/$w.Gallery.html#items

Shows the following example of how to manipulate items in a gallery:

let items = $w ( “#myGallery” ). items ;
items . push ( {
“src” : “wix:image://v1/68d3a9_1de7529c444b4c9eb38401f8efe0cad2.jpg/flowers.jpg#originWidth=1970&originHeight=1120” ,
“description” : “Description” ,
“title” : “Title”
} );
$w ( “#myGallery” ). items = items ;

But this doesn’t show you how to set the slug property.

If you have a Media Gallery field in a Collection, the data stored in the field is a JSON blob of Array of ImageItem. A dump of my Wix Collection shows the JSON blob in the code snippet below. The slug is set to something that resembles the Wix filename (without the ~).

[
 {
 "description":"",
 "slug":"c565a4_7e985bb77aa54cc2b121e60081056974mv2",
 "src":"wix:image://v1/c565a4_7e985bb77aa54cc2b121e60081056974~mv2.jpg/0001_sjpg#originWidth=600&originHeight=400",
 "title":"",
 "type":"image",
 "settings":[]
 },
 ...
]

If I want to manipulate, and then re-save Media Gallery columns in my Collection, how do I set the slug?

Hi :raised_hand_with_fingers_splayed:

The slug can be used in many cases where you need to get the download link of the image, we used to do it the hard way by using slice() and substr() to get this slug, now it’s built-in.

You don’t need to set it, and you won’t loose any functionality, the same goes about the title, you can ignore it too, these fields are just there if you need them.

So, it’s not required, and nothing will happen if you ignore it.

Hope this answers your questions~!
Ahmad

When you say “it’s built in”, what do you mean? Do you mean that if I call set item and don’t pass it in, something will set it for me?

No, it’ll be empty (null), when get items from a dataset, the dataset will auto fill it.

Thank you! This helps a lot.

I noticed when you have images with a slug and your set this information in a gallery, the slug property is lost…