Page templates
Contents
Create page templates to reuse a page across different content items.
Reusable pages
Previously, we mentioned that you’d get to know about the Templates
folder a bit later. The time has arrived.
With the current approach, you would have to configure a new page for every country in the list. A slightly more efficient approach is to use page templates. Page templates can be mapped to a specific content type i.e. "Country" - and all content items of type "Country" will be rendered by it.
Let’s take advantage over the fact that we have already created a page for a city.
-
Select, and Edit the City with the page
-
Select the page component, and from the context menu click Save as Template
-
Give your Template a suitable name i.e.
Country template
-
Choose
Country
in theSupports
dropdown.Here is a video demonstrating the process.
Now, when you select city content elements in the Content grid you’ll notice that each of them is rendered by the page template.
From scratch
Just like any other piece of content, a page template can also be created from scratch.
-
Select the
Templates
content item and then click new -
Select the
Page template
content type -
Select
Country
content type from the "Supports" dropdown. -
In the panel on the right select the
Hello Regions!
page -
Right click on
Drop here
region in the added page, thenInsert
andPart
and select theCity list
part. -
Then finally give this page template a name, such as "New Country Template" and save it.
Try clicking other countries to verify that the template actually works as intended. |
Automatic, fixed or customized
The country item you manually edited still uses the custom page you created - you can make it use the page template as well.
-
Edit the initial country, open the page editor and select the page.
-
From the right hand component view, change the Template setting from
Custom
toAutomatic
For every single content item, you can use Automatic (default), select a specific template or customize the page, "unlinking" it from its page template. |
You now have two page templates, both of which support "Country" content type. In this case "Automatic" mode will pick up the newest template, which is "New Country Template". If you want to use the old template, you need to select it explicitly. |
Summary
You’ve just learned about page templates, which is a way to reuse a page across specific content types within your site. This is a powerful feature of the CMS, as it enables editors to manage and publish page templates, just like any other content.
If you want to control the rendering of certain pages without using page templates, check out controller mappings. |
Next up, let’s see how to add and serve static assets, using the built-in asset service.