Display media gallery on dynamic page from URL

Hello, I have a digital magazine (converted from PDF) using an online publishing service which shows items that a reader can click a URL ( example: https://www.website.com/4aad66c8-1807-42ae-b479-12a9796eee7x ) using the primary ID of the item in my collection.

I am only getting the primary Photo1 to display in my #gallery1 . But, my collection has 8 image fields: Photo1; Photo2; Photo3; Photo4; Photo5; Photo6; Photo7; Photo8

Below is code that is currently working on a Lightbox page, but I can’t modify to work on another Dynamic Page I have created. The field name for my primary ID is “ID”.

import wixWindow from ‘wix-window’ ;
import wixData from ‘wix-data’ ;
// …

$w.onReady( function () {
let receivedData = wixWindow.lightbox.getContext();
let listingId = receivedData.listingId;
$w( ‘#dataset1’ ).onReady(() => {

    $w( "#dataset1" ).setFilter(wixData.filter() 
            .eq( "_id" , listingId) 
        ) 
        .then(() => { 

let item = $w( ‘#dataset1’ ).getCurrentItem();
let itemsForGallery = ;
for ( let i = 1 ; i < 9 ; i++) {
if (item[photo${i}]) {
itemsForGallery.push({ src: item[photo${i}] });
}
}
$w( “#gallery1” ).items = itemsForGallery;
$w( “#group1” ).show();
});
})
});

UPDATE: I found the below code that was from a similar previous post as mine that was marked SOLVED. I changed the variables and it does not display anything:

$w.onReady( function () {
$w( “#dataset1” ).onReady(() => {
console.log( “The dataset is ready” );
let item = $w( ‘#dataset1’ ).getCurrentItem();
$w( ‘#gallery1’ ).items = [
{ “src” : item.Photo1 },
{ “src” : item.Photo2 },
{ “src” : item.Photo3 },
{ “src” : item.Photo4 },
{ “src” : item.Photo5 },
{ “src” : item.Photo6 },
{ “src” : item.Photo7 },
{ “src” : item.Photo8 }
];
});
});

UPDATE #2 - I got the below code to work:

$w.onReady(() => {
$w( ‘#dataset1’ ).onReady(() => {
let item = $w( ‘#dataset1’ ).getCurrentItem();
let itemsForGallery = [];
for ( let i = 1 ; i < 9 ; i++) {
if (item[photo${i}]) {
itemsForGallery.push({ src: item[photo${i}] });
}
}
$w( “#gallery1” ).items = itemsForGallery;
});
})

Thank you for such a valuable information. I’ve been looking for a solution to this problem for a long time and I finally found one. Really appreciate your reply!