I would like the URLs in my dataset to be able to be connected to the “embed a site” option found under the “more” tab of the add option. It doesn’t allow my dataset to connect. My purpose is so that whatever the URL references to will show on each dynamic page.
Hi Brooke,
You can use HTML components for that.
Have a look here at the HTML component coding API.
Seems like you just need to get the URL out of the dataset current item and then set the HTML components ‘src’ attribute.
Hope this helps,
Liran.
Hi Liran,
Are you able to please give an example of the code that would be used in the HTML embed widget to access a URL in a dataset? For example, consider a database called ‘My_Database’ with two fields, the header of first field being ‘Title’ and the header of the second field being ‘URL’. The URL field is populated with the text ‘www.example.com/embed’. Can you please give an example of how we would write the HTML code for an HTML embed widget on a dynamic page so that we could access the URL field of My_Database to display www.example.com/embed?
Hi Daniel,
I assume you want this to happen as soon as the page loads.
Let’s say I have an entry there:
liran www.example.com
And let’s say that you have an HTML component called ‘#html1’.
Here’s a skeleton, adjust it to your needs:
import wixData from 'wix-data';
$w.onReady(function(){
const titleToFind = 'liran';
wixData.query('My_Database').eq('title', titleToFind).find()
.then(result => {
//check to see if we found the item
if (result.items.length > 0) {
const item = result.items[0];
$w('#html1').src = item.URL;
}
});
});
Hope this helps,
Liran.
Hi Liran,
Excellent, thank you. So, is the next step to place “src=item.URL” in the HTML component code? Are you able to please give a skeleton code example for the HTML component?
Hi Daniel,
I’m not sure I understand the question… but if you mean changing the code itself inside the HTML component, you don’t need to do that.
HTML component can have either HTML code or just a URL to load.
So the skeleton I provided is changing the URL itself (no need for HTML code) - it should be enough.
Liran.
Oh, OK. Great, thanks. I will try again.
HI Liran,
Still no luck. Are you able to please take a look at the page I am working on? I can send details via email and return here to post the solution.
Hi Liran,
Thanks for your help - I figured it out. If anyone is interested they can head over to this thread: