Totally new to Javascript/HTML and could use some help. I am building a database of personal information including Names, Photos, webiste links, social meida links, text, etc.
Photos are shown on a dynamic category page, and then clicking a persons photo will lead to a dynamic item page (that persons bio where all their information is pulled from the database). I would also like to store HTML code (unique to an individual) within some of the columns of the database and would like to execute it on the dynamic item pages somehow.
the wix built in html app does not allow linking to database as images/gallaries do. As the html will be different for each entry of the database, it does not look like i am going to be able to accomplish what i need within the editor, and will most likely need a bit of code
You can store the html inside a plain text field or RTF in the DB. If the html you are using is just a bit of markup, you can display it inside a text field, it supports a subset of html. Look here; https://www.wix.com/code/reference/$w.Text.html
If you need to do more than that, the html-component is your only option.
Good luck.
Thanks for the Response! An example of what i am trying to accomplish is displaying an individuals Amazon listing for his/her book/books on amazon within their dynamic item page. I have an amazon associates account which allows you to generate HTML code to display an amazon shopping “card” for any product/group of products. This is not supported within a text field/RTF. I will be storing the html code in database columns AmazonBook1…AmazonBook2…etc. My dynamic item page will have a number of blank html elements. lets call them HtmlBook1…HtmlBook2… etc. Is there a way through the “messaging” function to query the HTML code within AmazonBook1 column for the selected dynamic item page and send it to the htmlBook1 Element on the dynamic item page? I’m just starting to explore ways to accomplish this with code, I’m sure i’ll arrive at a solution eventually but any examples of code that would work for what i am trying to accomplish would be much appreciated!!
I just figured it out myself after 2 days of trying. Here it is. Replace the whatevernameinsidedivs with any name, like AmazonSource. Just don´t forget to replace it in the div id too if you do:
inside the html component you put this html:
<!doctype html>
2) Inside your Wix page, put this (replace datasetname, fieldname and iframenameonyourwixpage with your own names)
let urlMessage = $w('#Datasetname').getCurrentItem().fieldname;
$w("#iframenameonyourWixPage").onMessage( (event) => {
$w("#iframenameonyourWixPage").postMessage(urlMessage);
});
This will also get rid of the timing problem that I had. Hope it works for you.
@giri-zano Thanks a lot for the tutorial. That’s exactly what I needed!
I just want to add one thing for people that might encounter problems while setting this up.
I wasn’t able to get it working until I did these steps (after following all the steps you pointed in the tutorial):
And then I had to type the code from your part 2 like this (of course the event name, dataset name and iframe name need to be changed):
export function commandsHtml3_message(event) {
let urlMessage = $w('#commandsDataset').getCurrentItem().command;
$w("#commandsHtml3").postMessage(urlMessage);
}
Just leaving this here as it might help people who aren’t corvid experts.
@theredeng wondering if you can help me out in understanding the original code that girlzano posted. Specifically - what goes here in the code on the HTML element:
getElementById(“whatevernameinsidedivs”).innerHTML = event.data;
Very new to coding so not sure if that is the field name from the database or something else. Also, did you use a plain text field in the database to store your HTML? THANKS in advance!