# Dynamic Preview Url's referencing domain name from the space

**URL:** <https://forum.builder.io/t/dynamic-preview-urls-referencing-domain-name-from-the-space/5736>\
**Category:** Technical Questions\
**Created:** [June 5, 2024, 8:34pm UTC](https://forum.builder.io/t/dynamic-preview-urls-referencing-domain-name-from-the-space/5736 "2024-06-05T20:34:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhs129](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jhs129](https://forum.builder.io/u/jhs129)\
**Post date:** [June 5, 2024, 8:34pm UTC](https://forum.builder.io/t/dynamic-preview-urls-referencing-domain-name-from-the-space/5736/1 "2024-06-05T20:34:37Z")

</div>

I have a section called ‘practices’ that i have created and following the default example I have set the preview url to be dynamic using the following logic:

return `http://localhost:3000/practices/${content.data.name || '_'}`

This works but when I want to deploy the site to another domain I need to update the domain name in multiple places. Ideally I would rather update the domain name of the site on the space settings and then reference that value here. Something like:

return `${space.siteUrl}/practices/${content.data.name || '_'}`

I am sure this is possible but I need help figuring out the syntax. Please advise.

_Please fill out as many of the following questions as possible so we can help you promptly! If you don’t know how to answer or it does not apply, feel free to remove it or leave it blank._

**Builder content link**  
_e.g. [Builder.io: Visual Development Platform](http://builder.io/content/4cab34394e684fe7b93d6ef5493a8a51)_

**Builder public api key**  
_go to [Builder.io: Visual Development Platform](https://builder.io/account/organization) and copy your PUBLIC api key_

**What are you trying to accomplish**  
_e.g. I want to integrate builder on a landing page_

**Screenshots or video link**  
_Screenshots of your issue, or even better a link to a video of what is happening or what you are trying to accomplish. We love using loom for that sort of thing_

**Code stack you are integrating Builder with**  
_e.g. NextJS, react, Shopify_

**Reproducible code example**  
_If you are having integration errors, please link to codesandbox or copy and paste your problematic code here. The more detail the better!_

---

<div class="post-metadata">

**Author:** ![anon43891756](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@anon43891756](https://forum.builder.io/u/anon43891756)\
**Post date:** [June 6, 2024, 7:37am UTC](https://forum.builder.io/t/dynamic-preview-urls-referencing-domain-name-from-the-space/5736/2 "2024-06-06T07:37:06Z")

</div>

> [@jhs129](#):
>
> I have a section called ‘practices’ that i have created and following the default example I have set the preview url to be dynamic using the following logic:
> 
> return `http://localhost:3000/practices/${content.data.name || '_'}`
> 
> This works but when I want to deploy the site to another domain I need to update the domain name in multiple places. Ideally I would rather update the domain name of the site on the space settings and then reference that value here. Something like:
> 
> return `${space.siteUrl}/practices/${content.data.name || '_'}`
> 
> I am sure this is possible but I need help figuring out the syntax. Please advise.

Here is an example of using the `space` object in the Preview URL logic:

```auto
return `${space.siteUrl || 'http://localhost:3000'}/practices/${content.data.name || '_'}`

```

### Detailed Steps

#### Step 1: Add the `siteUrl` in Space Settings

1. **Navigate to Space Settings:**

- In the [Builder.io](http://Builder.io) interface, go to the **Settings** for your space.

1. **Add or Verify Site URL:**

- Make sure there is a site URL setting, commonly named `siteUrl`. If it doesn’t exist, you might need to add a custom field or set it in space settings directly.

#### Step 2: Use the `siteUrl` in Preview URL Logic

1. **Edit the Preview URL Logic for Your Section:**  
In the logic for your model’s preview URL, use the space setting:

```auto
// The default base URL
const defaultBaseUrl = 'http://localhost:3000';

// Use siteUrl from space settings or default to localhost
const baseUrl = space.siteUrl || defaultBaseUrl;

// Construct the full preview URL
return `${baseUrl}/practices/${content.data.name || '_'}`;

```

1. **Save and Test:**

- Save the settings and test your content preview. It should dynamically use the `siteUrl` defined in your space settings.

Let me know if this doesn’t help!
