I am looking at this article on the Gallery API in Magento2. I am testing the code samples in my browser

var api = $('[data-gallery-role="gallery"]').data('gallery');

However, this returns undefined... The first part does return an element


The later part is what seems to not be working as expected. Any idea what's wrong?


I figured it out. We are using a custom theme on this project, so navigating to


I found

<script type="text/x-magento-init">
        "[data-gallery-role=gallery-placeholder]": {

So in my case the code to access the fotorama api is

var fotorama = jQuery('[data-gallery-role=gallery-placeholder').data('gallery');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.