Embed website or html in Dynamic Page

Because I have so many pages in my website, I am attempting to use database collections and dynamic pages.

On my normal pages I have used the Embed tools. I have an html chart I display with the Embed html tool. And I display a webpage at the bottom of the page using the Embed website tool.

When I try to use those tools in a Dynamic page, there is no link available to get to the data in my database collection. Does anyone know how to embed html and embed a website to display in Dynamic pages?

Here is a link to an example of one of my pages:
https://www.birding-in-ohio.com/blendon-woods-metro-park

The “Bar Chart” table in the left columns is rendered from embeded html code.
The display from eBird at the bottom of the page is an embeded link to that page in eBird.

I would like to put these two elements on a Dynamic page but need help in how to accomplish that.
Ken Ostermiller

Hi,

Welcome to the Wix Code Forums.

Dynamic pages have a dynamic dataset which will give you access to the collection item of the dynamic page. You can then get the fields that you need - something like this:

let siteURL = $w('#dynamicDataset').getCurrentItem().siteURL;

I hope this helps,

Yisrael

Thanks, Yisrael. I will have to learn about that. Is there an article to which I could refer?

I still do not know how to embed html code or a website on a dynamic page. Those tools do not provide a way to link to the database collection field. Are you saying that I would insert the code you offered in place of the URL in the Embed Website tool?

See the docs on Dynamic Pages .

Hey Ostermik,

You know I just managed to do something that I hope it helps.

export function VirtualTourButton_click(event, $w) {
 let virtualtourlink = $w("#virtualtourlink").value;
 if ($w("#virtualtourlink").value.length > 0) {
        $w("#VirtualTourButton").label = "Cargando"
        $w("#CasasVdataset").setFieldValue("tour360Link", virtualtourlink)
        .then (() => {
            $w("#htmlVirtualTour").src = virtualtourlink;
            $w("#VirtualTourButton").label = "Listo";
        })
        .catch( (uploadError) => {
                $w("#VirtualTourButton").label = "Error al Cargar";
                console.log(`Error: ${uploadError.errorCode}`);
                console.log(uploadError.errorDescription);
            });
        }
}

To put you in context, I need to display virtual tours on some dynamic pages, so I used one of those html components, especifically the one that lets you embed a SITE (not the one that says html code). Now I have two types of dynamic pages, one which is displayed to my site’s visitors, and one that can only be seen by team members and is basically an input form with every detail of the property listing. The code you see is the one I used for the latter, and the difference is that this page must display the virtual tour in real time as in a preview of what visitors will see, so my team members can check if the tour is the right one and if everything is working fine with it, I haven’t tested yet on the other dynamic pages, the one for my visitors, but I’m pretty sure this will work in that case too.

I’ll explain (as far as I can) the code. First I placed an input field, which is set to accept URL’s only, the field is connected to the dataset (#CasasVdataset) which is connected to my database where I have a field with a fieldName ‘Tour 360 Link’ and a fieldKey ‘tour360Link’ (this is the one in grey that you can’t change). After this, I placed a button (a normal one not an Upload Button) for which I added an onClick event on the Properties Panel in the Editor. Once you do this, in the code section I wrote the code above, that basically reads if there is something on the input field, if true, then it changes the name of the button to ‘Cargando’ or ‘Loading’ and at the same time it sets the field value with the link that is on the input field. After that, it tells the html component ‘htmlVirtualTour’ that the site it must display is the one that was entered on the input field, and changes the button label to ‘Listo’ or ‘Ready’. The last part is just in case there is some error, it lets us know and also to my team member by displaying the button label ‘Error al Cargar’ or ‘Upload Error’.

Here are a couple of screenshots so you can relate what I wrote and have a better understanding.

This is the preview mode on the editor:

Here is how my code looks in case you need:


Now, the code should work on the dynamic pages that are meant to be seen by my visitors, of course it might change a bit, but you can use this as a reference, or I can copy it here once I build that dynamic page for my site.

In case this is confusing I’ll write next what things you must replace for the elements you decide to use:

#virtualtourlink: with your input field ID (the one you set in the properties panel)
#VirtualTourButton: with the button ID
#CasasVdataset: with your dataset name
“tour360Link”: with the fieldKey assigned to your field that holds the URL (remember the fieldKey is the one in grey that you can’t change)
#htmlVirtualTour: with your html component ID
virtualtourlink: this is the one you see after ‘let’ and you can name it as you want, of course you will have to change it on the other parts of the code too (right after “tour360Link” and after .src =)

And that’s it, I hope it is clear, as I said, this should work for you too, the only thing I think you will have to come up with is how to trigger it, because in this case I used a button. For now it occurs to me that you should place it inside the onReady page’s section, and maybe create an onReady function for the dataset too.

If you make it work let me know, and maybe share it here too. Good luck!!

Thanks.

Thx Rodney Please i want to ask if there is any way to Embed Twitter profiles in Dynamic Page

When we embed a html code in the RICH CONTENT field in Dynamic Pages and then PUBLISH the same, why does the PUBLISHED page NOT display the embedded code…?