If we comment out both of the above registrations, we get a different error for each page, which must indicate some kind of discrepancy:
This is because Page1 has the database column CMS_Document.DocumentPageTemplateConfiguration
already populated with the Page Template JSON for Page1. The value is going to look something like { "identifier": "namespace.page1" }
because that is what you specified in your registration attribute.
Since you don't have a Page Template registered with that identifier, it is erroring out.
However, Page2 does not have a value for this column. This means Xperience is using its standard approach for finding a way to render this page.
First it checks to see if any Controllers/Actions are registered for this Page Type. If it can't find any (which is your case), it tries to use its "Route to View" behavior, which looks for a Razor View file (.cshtml
) in a specific location. This location is /Views/Shared/PageTypes/PageTypeNamespace_PageTypeName.cshtml
. Since you don't have a View there, it is erroring out.
When you create a Page in the Content Tree, Xperience looks to see if any Page Templates have been registered that would be applicable to it by using the registered Page Template Filters. Page Template Filters are only used when working with pages in the Content Tree, not when rendering them on the Live Site.
If no Page Template is registered for the page, Xperience creates the page as a normal page and won't use Page Templates for it, unless it is recreated. This is because it is missing the CMS_Document.DocumentPageTemplateConfiguration
value. Since this value doesn't exist, Xperience doesn't falls back to normal Content Tree Routing.
If there is 1 Page Template registered for the page then Xperience auto-selects it when you create the page and stores that template's information in CMS_Document.DocumentPageTemplateConfiguration
.
If there are multiple Page Templates registered for that page, then you will be prompted to select 1. The selected Page Template's information will be stored in CMS_Document.DocumentPageTemplateConfiguration
.
If a page has CMS_Document.DocumentPageTemplateConfiguration
populated, it is a Page Template page, which means if you add/change Page Templates in the future, you can always switch to those. But the page won't ever be a normal page that uses Route to Controller or Route to View behavior.
I have a couple of recommendations for you if you want to use Page Templates.
-
Don't register a Page Template using the attribute overload that uses a separate Controller. The separate Controller won't bring you much benefit and complicates the setup of the Page Template. Instead, use the overload that only has a View path.
[assembly: RegisterPageTemplate(
"PROJECT_IDENTIFIER.HomePage_Default",
"Home (Default)",
typeof(HomePageTemplateProperties),
"Features/Home/HomePage_Default")]
-
Don't use the Page Type class name as the Page Template identifier! The real benefit of Page Templates is that you can have multiple for a single Page/Page Type. I recommend using a Page Template Filter to associate a set of Page Templates with pages of a specific Page Type. Use our Page Template Utilities package to simplify this process.
-
Check out my blog post covering the PTVC architecture, which is our preferred way of using Page Templates in Xperience. We've used this approach successfully for multiple projects.
-
If you need to switch a page from being a Route to View or Route to Controller page to a Page Template page (or go in the opposite direction), then add the DocumentPageTemplateConfiguration
field to the Page Type fields so that you can set/remove the correct JSON value for this field in the Content tab of the Page. This is especially helpful if the page is under workflow. If it's not under workflow then you can update the CMS_Document.DocumentPageTemplateConfiguration
value in the database directly.