I have a desire to connect a Dataset URL to a IFRAME element, but I don’t see the ability to connect the element to the dataset.
Thoughts anyone?
Teejay
I have a desire to connect a Dataset URL to a IFRAME element, but I don’t see the ability to connect the element to the dataset.
Thoughts anyone?
Teejay
hey @teejay - which component type are you trying to connect?
I basically have 28 shows over the year. We use a third-party ticketing system and we want to keep people at the site, even though they are buying their tickets at this service on a page set in an iframe.
Rather than creating 28 pages, was trying the content manager / dataset to see if I could dynamically generate these pages
Hi @teejay
You can do this using Velo.
I create a collection named ‘urls’.
It has field title and field url , which has URL to some site or page.
Add empty iFrame or use yours.
Here is the code snippet example.
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query('urls')
.eq('title', 'Youtube')
.find()
.then(res => {
$w('#iframe1').src = res.items[0].url;
})
});
Here is live site example.
https://vladkl4.editorx.io/my-site-5
Try it on your way.
You can improve code and add functionality you need.
Is this something you are looking for?
THANKS! I am continuously impressed. I will deploy a copy today.
What type of field is your STATUS field, please?
Thanks for your assistance, and I have a few more questions:
1. In this line of code:
. eq ( ‘title’ , ‘Youtube’ )
Do you need the secondary “Youtube”? Isn’t title sufficient, or would I have to add all the titles for each of my items?
After setting everything up, the iframe has a UNDEFINED server IP address error.
Thoughts?
Thanks, Teejay
@teejay Status field is something in testing process on my way, don’t mind.
Answers on your questions
After I get an object item from my collection, then I can get any other value of this item. Every item has ‘url’ property with its value, and Youtube item in my collection has ‘htttps://youtube.com’ url value.
I’ve underlined for you below in the code snippet all the values that for sure can differ for me and for you.
But please note that is only simple code snippet. The functionality can be much more difficult.
@vladkl in your case what is your collection name?
Here is what I have:
I have a URL field named Spektrix URL with Field Key of spektrixUrl
I have a title as The Nutcracker – Dec 4
The ID of the IFRAME element is “#spektrix”
And here is my Velo code
import wixData from ‘wix-data’ ;
$w . onReady ( function () {
wixData . query ( ‘spektrixUrl’ )
. eq ( ‘title’ , ‘The Nutcracker – Dec 4’ )
. find ()
. then ( res => {
$w ( ‘#spektrix’ ). src = res . items [ 0 ]. spektrixUrl ;
})
});
This why I asked about where to put the ID /Name of the Dataset which I have as #ticketData
My question how does this code know to pull from this dataset? THANKS IN ADVANCE FOR ALL YOUR TIME.
Hi. My collection’s name is “urls”
wixData.query('spektrixUrl') // wrong collection name
in this query() you should point the collection name as an argument. I guess your collection’s name is ‘Tickets’ ?
So the code should be
$w.onReady(function () {
wixData.query('Tickets') // collection name
.eq('title', 'The Nutcracker – Dec 4')
.find()
.then(res => {
$w('#spektrix').src = res.items[0].spektrixUrl;
})
});
What is #ticketData ? Is it a dataset id?
You don’t need the dataset when working with velo code.
By the way, this code is really custom. I mean that you point the item name (‘The Nutcracker – Dec 4’) manually
.eq('title', 'The Nutcracker – Dec 4')
But you can expand the functionality with velo and dynamically define the right name to retrieve.
Stuff like this
let ticket;
if (// some condition) ticket = 'The Nutcracker – Dec 4';
if (// some condition) ticket = 'The Nutcracker – Dec 20';
wixData.query('Tickets')
.eq('title', ticket)
.find()
.then(res => {
$w('#spektrix').src = res.items[0].spektrixUrl;
})
You can create a variable that under some conditions (you choose what conditions) can be one or another value. And this value should be equal to your title name.
Or another way
You can once retrieve ALL the items from the collection and change the array item under some conditions.
wixData.query('Tickets')
.find()
.then(res => {
console.log(res.items) // array of results. Every array item is a collection item
if (// some condition) $w('#spektrix').src = res.items[0].spektrixUrl
if (// some condition) $w('#spektrix').src = res.items[1].spektrixUrl
if (// some condition) $w('#spektrix').src = res.items[10].spektrixUrl
})
});
In this case you should check and know the order of items.
Or create your own way to define the correct name of a title in order to retrieve the url related to this title. You should know code to do that.
Hope that I’ve helped you