Simple text block link to URL in a collection

Hello, I’ve tried several versions of the below code and can’t the text block to link to a URL stored in a URL field called “dealer_website”? I have the text block successfully displaying just domain.com and want the click/link to go to https://www.domain.com/

import wixData from “wix-data”
import wixLocation from “wix-location”

export function website_click(event) {
[wixLocation.to(](wixLocation.to(“dealer_website”);
}) [“dealer_website”](wixLocation.to(“dealer_website”);
}) [);](wixLocation.to(“dealer_website”);
})
[}](wixLocation.to(“dealer_website”);
})

Hi :raised_hand_with_fingers_splayed:

Internal links must start with “/” … So just add it to your code:

wixLocation.to("/dealer_website")

But from what I can see, this link should by dynamic, and you’re not using the right way.

If the link is just a link field in your collection, get the current item from the dataset, and get the item’s link:

let item = $w("#myDataset").getCurrentItem();
wixLocation.to(item.link)

And if the link is a link to a dynamic page in your collection, get the current item as above and then access the link by it’s field key.

let item = $w("#myDataset").getCurrentItem();
wixLocation.to(item['dataset-link'])

Hope that helped~!
Ahmad

OK, I used the below code and got the below error code.

let item = $w ( “#myDataset” ). getCurrentItem ();
wixLocation . to ( item . link )

Wix code SDK error: The url parameter that is passed to the to method cannot be set to the value . It must be of type string.

Sorry, correction… my code:

export function website_click(event) {
let item = $w( “#dealersDataset” ).getCurrentItem();
wixLocation.to(item.link)

Please double check that you’re using the field key , not the field name, I think it’ll be dealerWebsite .

export function website_click(event) {
    let item = $w("#dealersDataset").getCurrentItem();
    wixLocation.to(item.dealerWebsite)
}

Yes, that worked great…thanks!

export function website_click ( event ) {
let item = $w ( “#dealersDataset” ). getCurrentItem ();
wixLocation . to ( item . dealer_website )
}

Sent you a note in FB Messenger

You’re welcome :wink: Glad that I helped
Happy Coding :computer: