# Lightbox with Dynamic Content via Button

**URL:** <https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 23, 2018, 8:28pm UTC](https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639 "2018-04-23T20:28:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![meia-ponta-capezio](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/meia-ponta-capezio/32/3303_2.png) [@meia-ponta-capezio](https://forum.wixstudio.com/u/meia-ponta-capezio)\
**Post date:** [April 23, 2018, 8:28pm UTC](https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639/1 "2018-04-23T20:28:58Z")

</div>

Hello all, I’m trying to connect a Lightbox with Dynamic content from a Repeater. I have a repeater that has a button so people can learn more about the content. I want to call a Lightbox upon clicking that button and it Dynamicly changes the content based on the selected data.

I already have a Dynamic Page for that purpose that works fine, but I prefer a lightbox instead.

PS: Every answer from previous posts are not complete enough for a Step-by-Step.

Thanks everyone in advance.

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [April 29, 2018, 1:03pm UTC](https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639/2 "2018-04-29T13:03:12Z")

</div>

Hi,  
You can use onItemReady, onClick, openLightboxand getContext methods.  
It should look something like this:

```javascript
import wixWindow from 'wix-window';
$.onReady(() => {
  $w("#myRepeater").onItemReady( ($w, itemData, index) => { 
    $w("#buttonElement").onClick(() => {
      const repeaterItem = itemData;
      wixWindow.openLightbox("LightboxName", repeaterItem);
    });
  });
});

```

In the Lightbox side:

```javascript
import wixWindow from 'wix-window';
$.onReady(() => {
  let receivedData = wixWindow.lightbox.getContext(); // will be equal to itemData
});

```

Checkout this thread:

> **[Dynamic Page Lightboxes | Velo by Wix](https://community.wix.com/velo/forum/coding-with-velo/dynamic-page-lightboxes)**
>
> Hi guys. How to create a dynamic lightbox with contact and detail info from the database?
> My site is a "room booking" kind. So when I click "book it now" a lightbox with info from the room should open.
> Any idea? Thanks.
> 
> ps: my site already has...

Good luck!  
Roi.

---

<div class="post-metadata">

**Author:** ![meia-ponta-capezio](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/meia-ponta-capezio/32/3303_2.png) [@meia-ponta-capezio](https://forum.wixstudio.com/u/meia-ponta-capezio)\
**Post date:** [April 30, 2018, 4:30pm UTC](https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639/3 "2018-04-30T16:30:35Z")

</div>

Thanks fot the answer **Roi** , but it does’nt work with my website.

Heres the code adapted to my context:

```javascript
import wixWindow from 'wix-window';
$w.onReady(() => {
  $w("#repeater1").onItemReady( ($w, itemData, index) => { 
    $w("#button1").onClick(() => {
      const repeaterItem = itemData;
      wixWindow.openLightbox("Escolas Preview", repeaterItem);
    });
  });
});

```

And here is the Lightbox:

```javascript
import wixWindow from 'wix-window';
$w.onReady(() => {
  let receivedData = wixWindow.lightbox.getContext(); // will be equal to itemData
});

```

It does show some data, but it shows the first line of the database, regardless of the button pressed.

Do I have to do something else? Can you explain this code so I can figure it out by myself? Do I have to say what repeaterItem is?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![meia-ponta-capezio](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/meia-ponta-capezio/32/3303_2.png) [@meia-ponta-capezio](https://forum.wixstudio.com/u/meia-ponta-capezio)\
**Post date:** [April 30, 2018, 9:08pm UTC](https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639/4 "2018-04-30T21:08:35Z")

</div>

**Roi** , I got it. The code you provided really sent the data from the repeater to the Lightbox. What was missing? How to handle the DATA!

I figured it out that you don’t need a DATASET inside de Lightbox, you just have to define its properties with data received using **receivedData.** After that it was really easy!

I’m going to post my code so anyone can see what was done.

```javascript
import wixWindow from 'wix-window';
import wixLocation from "wix-location";
$w.onReady(() => {
	let receivedData = wixWindow.lightbox.getContext(); // will be equal to itemData
	console.log(receivedData);
	$w('#logoescola').src = receivedData.foto; // Photo from Collection
  	$w("#nome").text = receivedData.title; // Title from Collection
  	$w("#endereco").text = receivedData.endereco; // and so forth
  	$w("#email").text = receivedData.email;
  	$w("#telefone").text = receivedData.telefone;
  	$w("#gmaps").location = { // this is to set the location on the maps object
		"latitude": receivedData.latitude,
		"longitude": receivedData.longitude, 
		"description": receivedData.title,
	};
	$w("#whatsapp").text = receivedData.whatsApp; // this is a text with hyperlink to a WhatsApp chat page
	$w("#whatsapp").onClick(()=> {
  		wixLocation.to("https://api.whatsapp.com/send?phone="+ receivedData.whatsApp+"");
	});
});

```

Thanks everyone, especially Roi!

---

<div class="post-metadata">

**Author:** ![dankeinandk](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@dankeinandk](https://forum.wixstudio.com/u/dankeinandk)\
**Post date:** [September 5, 2020, 7:42am UTC](https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639/5 "2020-09-05T07:42:26Z")

</div>

There’s a mistake in the code blocks you wrote, you are missing a “w” before the on ready function:

```javascript
$w.onReady(() => {
  let receivedData = wixWindow.lightbox.getContext(); // will be equal to itemData
});

```

---

<div class="post-metadata">

**Author:** ![mauppall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mauppall/32/27645_2.png) [@mauppall](https://forum.wixstudio.com/u/mauppall)\
**Post date:** [January 25, 2024, 1:25am UTC](https://forum.wixstudio.com/t/lightbox-with-dynamic-content-via-button/37639/6 "2024-01-25T01:25:59Z")

</div>

> [@meia-ponta-capezio](#):
>
> ```javascript
> $w('#logoescola').src = receivedData.foto; // Photo from Collection
> $w("#nome").text = receivedData.title; // Title from Collection
> 
> ```

Thanks for this.

I have a question here\>

Like you used .src for image and .text for text to display  
so the question is how to display the video, rich text, button text, media gallery?
