# Tweet button in project

**URL:** https://community.weweb.io/t/tweet-button-in-project/612
**Category:** How do I?
**Created:** [May 31, 2022, 3:49pm UTC](https://community.weweb.io/t/tweet-button-in-project/612 "2022-05-31T15:49:15Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)
#### Post date: [May 31, 2022, 3:49pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/1 "2022-05-31T15:49:15Z")

</div>

This might be a very basic question, but I am having some trouble. Essentially, I want to implement the [Tweet Button](https://developer.twitter.com/en/docs/twitter-for-websites/tweet-button/overview) 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.

---

<div class="post-metadata">

### Author: ![Edward](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/edward/32/249_2.png) [@Edward](https://community.weweb.io/u/Edward)
#### Post date: [May 31, 2022, 4:59pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/2 "2022-05-31T16:59:04Z")

</div>

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](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:

```auto
let uri = ADD YOUR COLLECTION VARIABLE HERE;
let encoded = encodeURI(uri);
let twitterLink = "https://twitter.com/intent/tweet?text=" + encoded;
return twitterLink;

```

 ![screenshot-editor.weweb.io-2022.05.31-17_57_16](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/6accc974ab7475e0d5a07f7a4851aacd947d9d51.jpeg)

---

<div class="post-metadata">

### Author: ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)
#### Post date: [May 31, 2022, 6:02pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/3 "2022-05-31T18:02:04Z")

</div>

![Screen Shot 2022-05-31 at 2.01.33 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/d70aa36a86b8d81d88cbe7f5c833f4a5a665b68e.png)  
ok thanks for this, i am getting an error with the JS formula… any ideas?

---

<div class="post-metadata">

### Author: ![Edward](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/edward/32/249_2.png) [@Edward](https://community.weweb.io/u/Edward)
#### Post date: [May 31, 2022, 6:13pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/4 "2022-05-31T18:13:37Z")

</div>

remove “return” from the beginning just before “let” and add “;” after selected variable, also add “;” after each line.

 ![screenshot-community.weweb.io-2022.05.31-19_13_52](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/e1b51caaecd3f2e109177eb54327ea145d7eb471.png)

---

<div class="post-metadata">

### Author: ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)
#### Post date: [May 31, 2022, 7:37pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/5 "2022-05-31T19:37:10Z")

</div>

![Screen Shot 2022-05-31 at 3.35.45 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/ee2b0631d805493826c96c900d79b3c59d650208.png)  
sorry about all of this still getting an error  
 ![Screen Shot 2022-05-31 at 3.58.09 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/81bbbf32ee3b8a93e545de639cf383d82cba9938.png)  
if I remove the “add”, I am getting this as a result (at least no error)

---

<div class="post-metadata">

### Author: ![Edward](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/edward/32/249_2.png) [@Edward](https://community.weweb.io/u/Edward)
#### Post date: [May 31, 2022, 7:58pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/6 "2022-05-31T19:58:34Z")

</div>

```auto
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.

---

<div class="post-metadata">

### Author: ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)
#### Post date: [May 31, 2022, 8:21pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/7 "2022-05-31T20:21:15Z")

</div>

ahhh haha ok … that worked, thank you!!!

---

<div class="post-metadata">

### Author: ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)
#### Post date: [June 1, 2022, 1:29pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/8 "2022-06-01T13:29:37Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)
#### Post date: [June 1, 2022, 1:40pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/9 "2022-06-01T13:40:50Z")

</div>

ah yes, thanks!

---

<div class="post-metadata">

### Author: ![Edward](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/edward/32/249_2.png) [@Edward](https://community.weweb.io/u/Edward)
#### Post date: [June 1, 2022, 1:53pm UTC](https://community.weweb.io/t/tweet-button-in-project/612/10 "2022-06-01T13:53:53Z")

</div>

It seems like the text needs to be encoded as per [Web Intent | Docs | Twitter Developer Platform](https://developer.twitter.com/en/docs/twitter-for-websites/tweet-button/guides/web-intent)

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.

> **[Conversion Filters](https://docs.xano.com/working-with-data/data-type-filters/conversion-filters#url_encode)**

> **[Text Filters](https://docs.xano.com/working-with-data/data-type-filters/text-filter#concat)**

So you have a few options 🙂
