Honestly, i’m super confused about how to call backend data and make it work on the front end when it isn’t an element that is directly connected to collection data. In my use case, I have a button that says “contact us” that i want to have open an email up, directed to the same email (no matter the dynamic page) but i want the subject to change depending on which page its on. I want the subject to say " Looking to book {‘fullName’}, where ‘fullName’ is a text field in my collection. I dont really understand how to go from data on the back end, to usable text on the front end!
import wixData from 'wix-data';
$w.onReady(function () {
wixData.get("Portfolio")
$w('#textSeriesName').text = "title";
$w("#button1").link = `mailto:agent@sophia.com?subject=Looking to book ${"#textSeriesName"}`;
});
Ha, okay maybe I’m using the terminology wrong. That aside, I need a piece of wix collection data (a text field) to Appear in my subject text for the email I’m coding in my dev console, and it needs to change depending on the dynamic page I’m on
import wixLocation from 'wix-location';
let path = wixLocation.path
$w.onReady(function () {
$w("#button1").link = `mailto:agent@sophiamodels.com?subject=Looking to book ${path}`;
});
Which opened an email to the right person, with almost the right subject, but the path ended up being longer than i wanted, so i tried what you said
with this:
let dbField = "title" //<<--- which DATABASE-FIELD //where "title" is the field key within the collection, and the collection ID is "Portfolio"
$w.onReady(function() {
$w('#dynamicDataset').onReady(()=>{
//where dynamicDataset is the name of my the dataset on my page
let currentItemData = $w('#dynamicDataset').getCurrentItem();
console.log("Current-Dynamic-Data: "
// should the " be on the other side of the :?
currentItemData);
$w('#textSeriesName').text = currentItemData[dbField];
$w("#button1").link = `mailto:agent@sophia.com?subject=Looking to book ${"#textSeriesName"}`;
});
});
When i clicked the button using this code, nothing opened up, but i feel like im getting closer haha!
this seems like it’s supposed to be something I’m naming, but i’m unsure of what element the ID its supposed to be referencing. From my (maybe misguided) understanding, the code is pulling the currentItemData, or the “title” data for the current dynamic page from my dataset associated with #dynamicDataset1, AND THEN, turning that title into a line of text that is being inputted in the subject line, which has been named #textSeriesName?
Ok, one more time!
Let’s make a little simple example…
Since i do not want to prepare a whole dynamic data-stuff and add a dataset, i just create my own example-data-object including some data… —> currentItemData