Cloudinary Product Gallery
Hello,
We are using Cloudinary Product Gallery - wondering if we can change the gallery position from an external swatch button?
Example image: The swatch icons on the right - can they control the gallery on the left?
-
Hi Rob,
The widget does not natively support this currently but there is a workaround you could implement using our Client-side list API (https://cloudinary.com/documentation/advanced_url_delivery_options#client_side_asset_lists) which lists all the assets in a given tag (e.g. https://res.cloudinary.com/<your_cloud_name>/image/list/25697194M-JJE90XX.json). Per notes, by default, the list delivery type is restricted. To enable it, open the Security settings in your Management console, and clear the Resource list item under Restricted image types. You may want to clear this option only temporarily, as needed. Alternatively, you can bypass this (and any) delivery type restriction using a signed URL.
Using this you can retrieve the total number of images in a particular tag and use that to dynamically assign a
startIndexvalue to each swatch.Here is an example I did: https://jsfiddle.net/tommygrg/83a297po/575/
So what I've done is:
- First, assigned contextual data called
color_codeto the images which correspond to their colour and then added all the required tags to an array calledtagList - Then I have a loop that goes over this array where I do a
GETrequest to the list API via thehttpGetAsyncfunction which then sends the json response toresHttpfunction - In the
resHttpfunction, I calculate the total number of images in that particular tag, add that total toallTagValuearray, this array keeps track of the total number of images in all the tags which I later use to calculate the correctstartIndex - Next, I retrieve the color hex value, when the loop initially starts we know
startIndexis0so I assign that value to the first button and then inject the relevant HTML code to the div with the idbtnAreawith the appropriate color id - Same logic applies after the first button is created but only difference this time is to get the correct
startIndex, I remove the last element fromallTagValuearray, assign it to a new array callednewTagArray, add all the values in thenewTagArrayand finally use this value as thestartIndex, this should then correspond to the correct coursel/image in the widget
Please let me know if you have any questions and hope this helps.
Kind Regards,
Thomas0 - First, assigned contextual data called
Post is closed for comments.

Comments
1 comment