Create image gallery with custom content


#1

Hi guys,

I am trying to use the cms-gallery attribute. Let’s say I have the following structure of code:

<a onclick=someFunction(1)><img src="other-pic.png"></a>
<a onclick=someFunction(2)><img src="some-pic.png"></a>

Is it possible to make it work with the dynamic count that I add to someFunction?

And more than that, is there any documentation that is written about cms-gallery? At this point I am trying to copy from the example website.

What I try to achieve is that my customer will be able to add/edit images, but I need to keep the structure above.

Thank you,
Eyal


#2

First, let’s make sure you’re referencing the right documentation! If you’re account was created before April 2019, you’re on version 5. Otherwise, you’re on version 7.

The version 5 gallery docs are located here:

The version 7 gallery docs are located here:


Those onclick attributes won’t be preserved. In fact, anything outside of what’s shown in the docs will be stripped when the gallery is regenerated.

You can, however, target gallery items with a script, just not inline. This is how the gallery tutorials work, so you can reference them for examples if you need to. Just make sure to prevent your script from running in the editor:

if (!window.isCMS) {
  // this block will not run in the editor
}