Lightbox on Dynamic page

I was wondering if someone might be able to help with this one, I have a button on a dynamic page which when clicked will show different light boxes depending on what page they are viewing. With the line .coursesCategory; this is the field key for the selection of what category the course is i.e. rock climbing, canoeing etc

I have the following code but can’t get it to work. Any help would be much appreciated.

export function button5_click(event, $w) {
	let activity = $w('#dynamicDataset').getCurrentItem().coursesCategory;
	wixWindow.openLightbox(activity);
}

Best wishes

Stephen

1 Like

Hi Stephen,

Does the coursesCategory field return the actual name of a Lightbox? You can verify by displaying the variable activity to the console like this:
console.log(activity);
Is the name that’s printed in the log the same as one of your Lightbox names?

Yisrael

Hi Yisrael,

This returns what you would expect from the code, the course category i.e. canoe holidays, rock climbing etc. I think this might be a little more difficult than I’m expecting. I was hoping to get the item of the ‘course category’ and then use this to open the correct lightbox to fit the course grade i.e rock climbing grades explained, canoe grades explained etc

Hi Stephen,

Don’t give up now - seems you’re almost there. You should just be able to assign these category names to the Lightboxes. So, you would have a Lightbox with the name canoe holidays . After you create a Lightbox, rename it to the name you want. I tried it and it works.

Yisrael

Hi Yisrael,

It works! I had tried renaming the lightboxes but I must’ve had a spelling mistake and/or the code wasn’t correct the time of testing! I was wondering if it would be possible to have a contains? i.e. if the course category contained ‘canoe’ canoe holidays, canoe intro etc then this would open the ‘canoe’ lightbox

Thank you for your help!

Stephen

YAY! Glad it worked out for you. :beers: