Link images collection to gallery dynamic page [SOLVE]

I have a collection with 3 fields, each with 1 image.
I want to link a gallery on a dynamic page to the collection images.

I’ve tried placing the code that Yoav gave as an example here .
My attempt is:

export function dynamicDataset_onReady() { 
   let item = $w('#dynamicDataset').getCurrentItem(); 
   $w('#gallery1').items = [ 
   {src: item.image1}, 
   {src: item.image2}, 
   {src: item.image3} ]; 
   }

but nothing is happening in the preview page. There are no console messages.

I think perhaps I’ve neglected an import statement, or maybe I’m placing the code altogether in a different page… right now it’s on the ‘page’ tab of the code editor in the dynamic page.

Any help would be appreciated.Thank you.

Hi Yafim,

Need more information in order to help. What components do you have on your page? What other code do you have?

Yisrael=

Hi Yisrael,

The code I posted is the only code I have on the page.
Besides the gallery I have some other text boxes, background fills and a few buttons that link to documents.
I don’t think it has anything to do with it…

Perhaps I am missing something from the code, like a top-level function…?

Please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor.

Can you access this?:

Your dataset’s onReady() function was never called. As an example, you can include it in the page onReady() function.

$w.onReady(function () {
   $w("#dynamicDataset").onReady(() => {
   console.log("The dataset is ready");
   let item = $w('#dynamicDataset').getCurrentItem();
   $w('#gallery1').items = [
            { "src": item.images },
            { "src": item.image2 },
            { "src": item.image3 }
        ];
   });
});

As you can see in the above code, the Field Key of the first image was incorrect - it needs to be images (not image1).

I tried this and it runs fine.

Good luck,

Yisrael

1 Like

Thanks for the help Yisrael! It works.