Skip to main content

Plan your Template URLs

Plan your Template URLs before you create templates. When every address on your site fits one template, Studio picks it at once, and your live site shows the template you meant at every address.

The example on this page is the team blog: the Blog post template at /blog/{{entry.slug}}, News article at /news/{{entry.title}}, and the freeform About template at /about. Say your site also has a freeform Home template and a Landing page content type for marketing pages such as /pricing.

A site map where each address fits one template​

Your marketing team makes pages such as /pricing as Landing page entries. Editors write posts under /blog and news under /news. Here is a set of Template URLs where no two templates compete for an address.

AddressTemplateTemplate URLWhy it's set this way
/Home, freeform/A variable can't match /, so the home page is fixed text.
/aboutAbout, freeform/aboutFixed text. It wins over the top-level template below.
/pricingLanding page/{{entry.url}}The one template at the top level.
/blog/ai-101Blog post/blog/{{entry.slug}}Nested under /blog, so it has a prefix.
/news/how-ai-worksNews article/news/{{entry.title}}Nested under /news, so it has a prefix.

Five addresses, each going to one template. / goes to the freeform Home template at /, and /about to the freeform About template at /about, both fixed text. /pricing and /summer-sale go to Landing page at /{{entry.url}}, the one top-level template. /blog/ai-101 goes to Blog post at /blog/{{entry.slug}}, with the prefix /blog/, and /news/how-ai-works to News article at /news/{{entry.title}}, with the prefix /news/.

Two rules make this work: one template at the top level, and a prefix for everything nested.

Keep two templates off one URL​

Most shared URLs are accidents. Each template looks right on its own, and the clash shows up only when two of them fit the same address. Five rules keep every address to one template:

If two templates do end up at one URL, see what Studio, Deploy and your live site do in When two templates share a URL.

One template at the top level​

A Template URL with nothing in front of {{entry.url}}, such as Landing page's /{{entry.url}}, serves top-level addresses like /pricing. {{entry.url}} matches the whole address, so this template fits every address on your site. See Why entry.url matches the whole address.

That's fine for one template. A template with more fixed text, such as Blog post's /blog/{{entry.slug}}, still wins its own addresses, because Studio picks the closest match first. Landing page gets only the addresses nothing else fits.

The address /blog/ai-101 goes through two steps. In step 1, the shortlist, Featured post's /blog/featured doesn't fit, /{{entry.url}} drops out with less fixed text, and Blog post's /blog/{{entry.slug}} stays, so Blog post wins. Step 2, the entry check, runs only when more than one template stays.

Give only one template a top-level Template URL. Say the product team also gives a Product content type /{{entry.url}}, and both teams publish an entry at /summer-sale:

  • Both templates fit every address, so Studio has to check each one for an entry.
  • The canvas shows the notice Multiple Templates Use This URL.
  • Your live site serves whichever template was deployed most recently.
  • Deploy doesn't stop it, because the two templates are on different content types.

See When two templates share a URL.

The home page can't use {{entry.url}}, because a variable needs at least one character and / has none. Give the home page the Template URL /. A freeform page such as About at /about is fixed text, so it wins over /{{entry.url}} at its address.

A prefix for everything nested​

Every address below the top level gets a fixed prefix in its Template URL, such as /blog/ and /news/. The prefix tells the templates apart. With /blog/{{entry.url}}, Studio still looks up the whole address in the URL field, but only Blog post fits addresses that start with /blog/. Studio settles the template at the first step and skips the entry check. See Which template wins when several match.

Set the prefix where the URL comes from​

Set the prefix in Contentstack, on the content type, not in Studio. Studio takes a template's URL from the content type's Custom Preview URL row, or else its URL pattern. Put the prefix there, and Studio picks it up on its own:

  • Every template on the content type gets it, including ones you create later. You don't edit any URL in Studio.
  • Visual Editor and Live Preview open the same address, because they read the same source.
  • When you change the prefix later, every template follows the next time you open it.

On the Blog post content type in Contentstack, the prefix comes from its Custom Preview URL row /blog/{{entry.slug}}, which wins when it exists, or else from the URL field's Prefix /blog/. Studio derives the Template URL /blog/{{entry.slug}} from it each time a template opens, so the Blog post template, a second template on Blog post, and Visual Editor and Live Preview all open /blog/ai-101. A URL typed in Edit URL stops following the source.

Set it in whichever source your content type uses. The Custom Preview URL wins when it has a row for the content type.

Your content type's URL comes fromSet the prefix here
The Custom Preview URLIn Settings, then Visual Experience, then Preview URL, give the content type its own row whose path starts with the prefix, such as /blog/{{entry.slug}}, not /{{entry.slug}}. See Use a Custom Preview URL with Studio.
The content type's URL patternIn the URL field's URL Properties, set Prefix, such as /blog/. Studio builds /blog/{{entry.url}}. Contentstack also adds the prefix to every entry's URL field, so the two stay in step.

To see which one a template uses, see Where the Template URL comes from.

Type a URL in Edit URL only for the one template that has to differ. A URL you type no longer follows its source: when you change the Custom Preview URL or the URL pattern, that template keeps what you typed, and the Custom Preview URL's transformation rules stop applying to it. To follow the source again, reset the URL. See Go back to the derived URL.

When the URL field holds a full address, the prefix has to be how that address starts. AI 101's URL field holds /blog/ai-101, so /blog/{{entry.url}} is right. With /topics/{{entry.url}}, the canvas opens /blog/ai-101 and ignores /topics. Setting Prefix on the URL field avoids this, because Contentstack writes the prefix into every URL it generates.

One template per content type​

A content type usually needs one template. Its Template URL comes from the content type's Custom Preview URL row or its URL pattern, so a second template on the same content type gets the same Template URL. Studio doesn't warn you when you create it.

The exception is a redesign. Build the new layout as a second template at the same URL, and deploy it as a secondary template. Visitors keep seeing the primary template, and reviewers open the new one from its link on your live site. Until you deploy, each template shows on the canvas when you open it. For the steps, from the first deploy to the swap, see Review a redesign, step by step.

Write every address the same way​

Where to go next​

Report a problem with this page