Naming convention for URL PageType folder views

Mike Young asked on December 10, 2020 18:52

Hi I just wanted to share that I got tripped up a bit on this page when naming a view file https://docs.xperience.io/developing-websites/implementing-routing/content-tree-based-routing/setting-up-content-tree-based-routing

I was following these directions:

In your MVC project, create a view under Views/Shared/PageTypes. The view needs to be named after the class name of the created page type. Replace the period ('.') separator between the page type namespace and code name with an underscore ('_'). Based on this convention, the system automatically matches requests for pages of a particular page type to the corresponding view.

For example: assuming you have a page type called MySite.Article (namespace.codename), name the view "MySite_Article.cshtml". The full path to the view is then: ~/Views/Shared/PageTypes/MySite_Article.cshtml

I had a class generated by the admin site named "BlankWithNav" and the generated namespace was CMS.DocumentEngine.Types.Custom. Following those direction I thought the file should be named "CMS.DocumentEngine.Types.Custom_BlankWithNav.cshtml" but through runtime errors I saw the site was actually looking for "Custom_BlankWithNav.cshtml". I didn't see anywhere in the instructions that it would just be looking for the tip of the namespace rather than the full name.

Correct Answer

Sean Wright answered on December 15, 2020 01:08

Yeah, that is confusing. The 'namespace' term is a bit overloaded in Xperience.

In Xperience there is a difference between the Page Type namespace in the database and the Page Type C# class namespace in your custom code.

The database namespace is whatever you type into the "Namespace" field when creating a new Page Type.

The code that the CMS auto generates for you in the "Code" tab of the Page Type includes the C# namespace CMS.DocumentEngine.Types as a prefix to every auto generated class, with your Page Type namespace following that prefix.

If you look for your Page Type definition in the CMS_Class database table, you can see what Xperience considers to be the 'full name' (namespace + class name) in the ClassName column.

Everything before the . is the 'namespace' and everything after is the Page Type name.

1 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.