This might be a very basic question, but I am having some trouble. Essentially, I want to implement the Tweet Button where the Tweet text is dynamically populated by data returned from a rest API call. I have the data in a collection from the rest API and I thought to enter the Tweet Button code as an HTML block. I am having some trouble figuring out how to write a formula that <a class="twitter-share-button" href="https://twitter.com/intent/tweet?text=Hello%20world"> Tweet</a>
would replace the “hello world” with the text from the rest API.
Hi @nocodedevs ,
I would not necessarily use custom HTML for this. You can simply add a button to your page > Link formula: https://twitter.com/intent/tweet?text=SELECT API VARIABLE HERE
and add the relevant API variable at the end of the link
ps: Assuming your text is not encoded, you might need:
Link javascript formula:
let uri = ADD YOUR COLLECTION VARIABLE HERE;
let encoded = encodeURI(uri);
let twitterLink = "https://twitter.com/intent/tweet?text=" + encoded;
return twitterLink;
remove “return” from the beginning just before “let” and add “;” after selected variable, also add “;” after each line.
sorry about all of this still getting an error
if I remove the “add”, I am getting this as a result (at least no error)
let uri = VARIABLE;
let encoded = encodeURI(uri);
let twitterLink = "https://twitter.com/intent/tweet?text=" + encoded;
return twitterLink;
Replace the word “VARIABLE” with the actual variable
I now see your second response. Sorry if I was not clear on my previous messages. When I said add “;” I meant add “;” only, not the word “add” + “;”
your 2nd screenshot looks good. Once variable has a value it should be populated after the link.
ahhh haha ok … that worked, thank you!!!
You can also use the link with nocode formula, and concatenate the start of your url with your variable (if you do not have to encode it)
ah yes, thanks!
It seems like the text needs to be encoded as per Web Intent | Docs | Twitter Developer Platform
However you can also handle that in Xano, then pass the encoded text to Weweb and then use the nocode formula to concat the firts part of the URL with the URL encoded text from Xano.
OR even better:
URL encode the text in Xano and concat the URL in Xano as well, and send the whole URL to Weweb, then simply connect the constructed URL from Xano to the button. In this case the whole process is in your backend.
So you have a few options