Is It Possible To Link Dynamic Pages to a Button?

I keep trying to link a dynamic page to a button, however it is grayed out and isn’t letting me select it. Is there a way to make this either a)possible, or b) an easier way to set up personal blogs for members on my website? Thank you!

Hi @stormienihongo , yes you can but with code.

Let’s assume that your button id is ( button1 ), if you’re on a dynamic page that uses the database fields to build its URL, or if you’re using a repeater, I’ll give you a sample code for each of the previous options.

1. Set dynamic links on a dynamic page

Assuming that the dynamic page is a profile page that contains the people data, including their social media links, and you want users who click on ( button1 ) to be redirected to the profile owner’s Facebook page.

Let’s assume that you’re using a dataset ID called ( dataset1 ), use the following code

$w.onReady(async function () {
    $w('#dataset1').onReady( () => {
        let item = $w('dataset1').getCurrentItem();
        let username = item.username;
        
        $w('#button1').link = `https://facebook.com/${username}`;
        $w('#button1').target = "_blank";
    }
})

What do you need to change? You only need to change the orange text with your dataset ID, and the brown text with your button ID.

1. Set dynamic links on Repeaters

To set dynamic links on a repeater, you need the repeater’s ID, and you need its onItemReady(). function, for this example I’ll use two buttons, one that redirect to Facebook (facebookButton), and the other to Twitter (twitterButton), and the repeater’s ID will be (repeater1).

I’ll assume that your purpose is the same as above, you have a repeater that contains some friends profiles as the repeater data, and you have a button on the repeater that will redirect whoever clicks on it to the profile page of the person card that its button was clicked on.

$w('#repeater1').onItemReady( ($item, itemData
) => {
    let username = itemData.username
    
    $item('#facebookButton').link = `https://facebook.com/${username}`;
    $item('#twitterButton').link = `https://twitter.com/${username}`;
})

Notice that on repeaters, we use the $item selector instead of the regular selector $w.

What do you need to change? You only need to change the brown text with your buttons’ IDs.

I hope that helps :kissing_smiling_eyes::wink:

Ahmad.

Thank you so much! It really has

@stormienihongo Glad to hear that :wink:
If you need further questions don’t hesitate to ask.