Hi there, I need help on dynamic lightbox code.
I’ve built a dynamic page connected to a dataset. The user sees a different version depending on the URL they follow. In the page is a repeater with nine containers, each housing a button and some text. Each button should open a different lightbox.
I want to make the lightbox content dynamic, depending on the version of the dynamic page the user lands on. I only have five elements in the lightbox: title text / copy / image / image text / and a link-out URL (when tapping on the image).
I’ve managed to put some code in that partially works. It shows no errors and works in the live page based on what I’ve told it to do. But it’s not doing what I want it to do because my code is deficient.
My problems:
-
The button opens the lightbox but shows content from the first line in the dataset. It’s not dynamic. How do I tell it to look up the line that relates to the version of the specific dynamic page the user is in?
-
Every button I’ve added to the containers in the repeater has the same name. How do I have a different button name in each container of the repeater so each button can open a different lightbox?
-
How do I add a URL to the image in the lightbox? I’ve added text and image. Now I need a way for the user to tap the image and link out to a web page (again, URL is from the dataset and is different depending on the version of the dynamic page)
I have other questions but these are my big ones. Please help!
Here’s where I’m at…
//dynamic page:
import wixWindow from 'wix-window';
$w.onReady(() => {
$w("#dynamicDataset").onReady(() => {
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item('#button45').onClick(() => {
let item = $item('#dynamicDataset').getCurrentItem();
wixWindow.openLightbox('TEST.Stories.6S.Explore.T4', item)
});
});
});
});
//where dynamicDatset is the collection in the dynamic page
//where button45 is a button in the repeater
//where 'TEST.Stories.6S.Explore.T4' is the lightbox name
//Lightbox;
import wixWindow from 'wix-window';
$w.onReady(function () {
let receivedData = wixWindow.lightbox.getContext()
$w("#text285").text = receivedData.lb4Title
$w("#text287").text = receivedData.lb4Copy
$w("#image69").src = receivedData.lb4Image
$w("#text286").text = receivedData.lb4ImageText
});
//where text285 is the title textbox in the Lightbox
//where lb4Title is the field ID in the dynamicDataset (from the dynamic page)