I have created a dynamic page. One of the text connected to the database and obtaining so-called “message” from the database. The “message” successfully extracted from database based on the “ID”.
Meanwhile, I have created a button which allow visitors share my page through WhatsApp. I wish the “message” can be attached in the content in WhatsApp message. The question is how I can obtain the value of the “message” in this dynamic page?
I think what you’re looking for is this reference:
https://www.wix.com/corvid/reference/wix-dataset.DynamicDataset.html#getCurrentItem
This allows you to get the current item (ie, the current page setup), and then everything in your database would be stored in key/value pairs.
So if you have a ‘message’ key (the keys are the names of each column in your database), then you could get the message of the current item with something like
$w.onReady( () => {
$w("#myDataset").onReady( () => {
let message = $w("#myDataset").getCurrentItem().message;
} );
} );
Then, the variable “message” would contain the message defined in your database field ‘message’ for the item you’re currently accessing. Then, when it’s in your code, you can use it however you like.
Alternatively, you could tie your to a hidden text object on the page, get that object with a normal selector ($w(‘#hiddenText’)), and then in your code you could deal with it from there. If you just need the text without any formatting, you can get it by adding ‘.text’ at the end, so something like the below:
let messageText = $w('#hiddenText').text