Use a Custom Preview URL with Studio
Your stack's Custom Preview URL tells Studio, Visual Editor and Live Preview where each entry lives. In Studio it decides which site the canvas opens a template on, and how each entry's address is shaped. Read this page when your stack has a Custom Preview URL. It shows how to get the canvas and your site to the same page at the same address.
You set it up in Contentstack, in Settings, then Visual Experience, then Preview URL. It has base URLs, each with an alias, a URL path for each content type and branch, and transformation rules under Advanced Config. To set these up, see Contentstack's Custom Preview URLs guide.
Studio follows the same rules as Visual Editor and Live Preview. It uses the URL path set for the template's content type ahead of one set for all content types. A path with no branches counts for every branch. Studio always uses the paths for the main branch, whichever branch you work on, while Visual Editor and Live Preview use their own branch. If no path fits, Studio uses the content type's URL pattern, then the default. See Where the Template URL comes from.
The examples on this page come from the team blog. Blog post's path is /blog/{{entry.slug}}. News article's path is /news/{{entry.title}}, with two transformation rules. The stack has three base URLs: Local, Production and Local by language.
Base URL aliases
A base URL is the site part of a page's address, such as http://localhost:3000. Each base URL in the Custom Preview URL has an alias, the name you pick it by, such as Local.
How Studio applies an alias
Studio opens the canvas on the alias's base URL, followed by the template's path. For AI 101 on the Blog post template:
| Alias | Base URL | AI 101 opens at |
|---|---|---|
Local | http://localhost:3000 | http://localhost:3000/blog/ai-101 |
Production | https://www.example.com | https://www.example.com/blog/ai-101 |
- Which templates use it. Only a connected template whose URL comes from the Custom Preview URL. Every other template, and every section, opens on the environment's base URL, as before. So does any template when the Custom Preview URL has no base URLs.
- Which alias. Studio uses the first alias in the list until you pick another. If the alias you picked is deleted or renamed, Studio goes back to the first one.
- Where you pick it. In the canvas Configuration dialog, in Alias. The field shows only while a template that uses an alias is open. Your pick is saved in your browser only, so other people keep the first alias. See How the canvas Configuration dialog differs.
Your live site doesn't use the alias. Your own domain answers the address, and your route passes Studio the path.
Base URLs with and without variables
A base URL without variables, such as http://localhost:3000, needs nothing from your site. The catch-all route passes the path, /blog/ai-101, as it is.
A base URL can also hold {{environment}}, {{locale}} or an entry field, such as http://localhost:3000/{{locale}}. Studio fills {{environment}} from the environment in the Configuration dialog, and an entry field from the preview entry. It fills {{locale}} from Visual Editor's language, or else the template's master language. The Language in the Configuration dialog doesn't fill it.
With Alias set to Local by language, AI 101 opens at http://localhost:3000/en-us/blog/ai-101, because English is the master language. Picking French as the Language in the Configuration dialog doesn't change that address.

Studio matches the path your route passes, exactly. It doesn't remove any part of a base URL from it. So when the language is part of the base URL, your route takes it off the path. For /en-us/blog/ai-101, it passes Studio /blog/ai-101, with en-us as the locale option. For the route code, see Put the language in the address. For everything else a base URL can add in front, see Pass Studio only the path the Template URL describes.
If a variable has no value, or the base URL doesn't make a valid address, the canvas shows an error instead of your page. See If it doesn't work.
Transformation rules
A transformation rule changes a field's value before it goes into the address. You add rules under Advanced Config, one for each field, such as entry.title. A rule applies wherever that field appears in your paths.
News article's path is /news/{{entry.title}}, with two rules on entry.title:
- Lowercase.
- A Regex that replaces each space with
-.
Studio applies the rules when it opens the News article template, so Machine Learning Explained opens at /news/machine-learning-explained. The template keeps its Template URL, /news/{{entry.title}}, so a change to a rule needs no change to the template. Studio reads the rules when you open a template. If you change a rule while Studio is open, reload Studio to pick it up. Without a reload, Studio can keep the old rules for up to 15 minutes.

After a rule runs, Studio encodes the value. A / in a rule's result stays inside one part of the address: a map rule that turns Tech News into news/tech gives /news/news%2Ftech.
Transformation rules apply only inside the Custom Preview URL
The rules belong to the Custom Preview URL. Studio applies them only to a template whose URL comes from it.
A template whose URL comes from anywhere else gets no rules, even on the same content type. That covers a URL you typed in Edit URL, and a URL from the content type's URL pattern. Studio fills these with each field's stored value. Type /news/{{entry.title}} in Edit URL and save, and Machine Learning Explained opens at /news/Machine%20Learning%20Explained.
When you type a URL that uses a field with a rule, Edit URL says:
"You changed this URL, so it no longer follows the Custom Preview URL, and its rules won't apply to the variables. Use reset (↻) to follow it again."

To use the rules again, reset the URL. See Go back to the derived URL.
How to fetch a page whose address uses transformation rules
The rules shape an address in one direction, from the entry to the address. Studio, Visual Editor and Live Preview apply them, so they open Machine Learning Explained at /news/machine-learning-explained.
When your route asks Studio for a page by its address, Studio matches the address against the values stored in your entries. It doesn't apply the rules there. No News article stores machine-learning-explained, so a fetch by url, or by compositionUid with url, finds no entry. It fails with an error that starts like this:
[Contentstack Studio] ENTRY_NOT_FOUND: No entry was found for the content type "news_article" this composition is connected to.
So your route goes the other way itself. It undoes the rules to get the title back, finds the entry with that title, and tells Studio both the template and the entry: the Template UID as compositionUid, and the entry's UID as templateEntryUid.
Undo the rules, last rule first
Undo each rule in the reverse order it ran:
- The Regex replaced each space with
-, so replace each-with a space.machine-learning-explainedbecomesmachine learning explained. - Lowercase dropped the capitals, so put a capital at the start of each word. You get
Machine Learning Explained, the title as stored.
This works because the News article titles follow a convention the rules don't break: every word starts with a capital, and no title has a - of its own. A title outside the convention doesn't come back. "How AI Works" opens at /news/how-ai-works, but the reverse gives "How Ai Works", which matches no entry, so that address answers 404. Keep your titles to the convention, or pick rules your titles can come back from.
Fetch the template with the entry you found
Give the shaped addresses a route of their own. It turns the address back into a title, asks the Delivery SDK for the News article with that title, and passes both UIDs to Studio:
// app/news/[slug]/page.tsx
import { notFound } from "next/navigation";
import { sdk, stack } from "@/lib/contentstack";
import { TemplateRenderer } from "../../[[...slug]]/template-renderer";
type Props = {
params: Promise<{ slug: string }>;
searchParams: Promise<Record<string, string>>;
};
// Undo the News article rules, last rule first:
// "-" back to a space, then a capital at the start of each word.
function titleFromSlug(slug: string) {
return slug
.split("-")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ");
}
export default async function NewsArticlePage({ params, searchParams }: Props) {
const { slug } = await params;
const searchQuery = new URLSearchParams(await searchParams).toString();
const { entries } = await stack
.contentType("news_article")
.entry()
.query()
.equalTo("title", titleFromSlug(slug))
.find<{ uid: string }>();
// No entry, or two with the same title: answer 404, never guess.
const entry = entries?.length === 1 ? entries[0] : undefined;
if (!entry) notFound();
const specOptions = await sdk.fetchCompositionData(
{ compositionUid: "news_post", searchQuery },
{ templateEntryUid: entry.uid },
);
return <TemplateRenderer specOptions={specOptions} />;
}
For /news/machine-learning-explained, titleFromSlug gives Machine Learning Explained, the query finds that entry, and the page shows the News article template with it.
- The route.
app/news/[slug]/page.tsxanswers every/news/address before the catch-all does. titleFromSlug. Undoes your rules. Write it to match your own rules, in reverse.stack. The Delivery SDK stack fromlib/contentstack.ts.equalTomatches the stored title exactly, capitals included.compositionUid. The News article template's UID,news_post. It's in the template's Edit Template dialog.templateEntryUid. The UID of the entry the query found for this request, never a fixed one. Inside Studio, the preview entry the author picks still wins over it.TemplateRenderer. The client component from your catch-all route. Add the template's styles and meta tags the way the catch-all does. See Render on the server with the Next.js App Router.
When no entry has the title, notFound() answers 404.
Pass compositionUid without templateEntryUid only when the content type has a single entry. Otherwise Studio uses the first entry the Delivery API returns, so every address on your live site shows that one entry. The canvas still looks right, because inside Studio the entry the author picks takes the place of templateEntryUid.
The same fetch fits any route that already knows its entry, not only one for shaped addresses. Ways to fetch a template sets it beside the other ways a route asks Studio for a template. They include compositionUid alone, for a content type with one entry. See Fetch a template and an entry by UID.
Before you go live
- Two entries can share one address. Lowercase, a Regex that removes characters, Join or Default can give two entries the same address. The route above answers 404 when two entries have the same title, rather than guess between them.
- Build your links the same way. Write one function that applies the same rules, and use it for links, the sitemap and canonical tags. Then your links match the addresses Studio opens.
To check it, open Machine Learning Explained at /news/machine-learning-explained on your site and on the canvas. Change one letter of the address, and the page answers 404, never another entry.
If it doesn't work
-
The canvas says "This Page Has No Content to Show", and your site answers 404 at
/news/machine-learning-explained. The route fetches the shaped address byurl, and no entry stores that value. Fetch by the template and the entry instead, as in How to fetch a page whose address uses transformation rules. Read No entry has this address for the other causes. -
The canvas shows a News article, but your site answers 404 at its address. The title doesn't come back from the address, such as "How AI Works", which comes back as "How Ai Works". Change the title to the convention, or change
titleFromSlugand the rules together. See Undo the rules, last rule first. -
Every address on your live site shows the same entry, but the canvas looks right. The route passes
compositionUidwithouttemplateEntryUid, and the content type has more than one entry. Pass the entry's UID too. -
The canvas says "No entry matches this URL pattern", and names a base URL alias. The alias's base URL uses an entry field, such as
{{entry.summary}}, and Studio fills only the fields the Template URL uses. Use only{{environment}}and{{locale}}in an alias's base URL, or pick another alias. Read No entry fills the URL pattern.
-
The canvas says "Invalid Custom URL". The alias's base URL doesn't make a valid address, such as one without
http://orhttps://. Fix it in Contentstack, under Preview URL, then Base URL, or pick another alias. Read The Base URL alias doesn't make a valid address. -
The canvas opens the template on the environment's base URL, not on an alias. The Template URL doesn't come from the Custom Preview URL, or the Custom Preview URL has no base URLs. Reset the Template URL. See Go back to the derived URL.
-
The template uses the content type's URL pattern or the default, though the Custom Preview URL has a path for its content type. The path uses a variable Studio can't fill, so Studio skips it. Use only the variables in Variables a Custom Preview URL can use.
-
No entry matches an address whose path uses
{{entry.author.handle}}. The path's include list for the content type doesn't nameauthor. Add the reference to that path's include list in the Custom Preview URL.
For a card or log code this page doesn't list, find it on the Errors pages.
Where to go next
- Change a Template URL, or reset it: Edit or reset a Template URL.
- Wire your routes: Wire template preview routes.
- Pick an alias, environment and language for yourself: How the canvas Configuration dialog differs.