Page templates and layout files

Each website has one or more default layout files that define the general structural division of pages into sections. A layout file and its section placeholders serve as the basis, on which Sitefinity CMS and the view engines construct views and render the proper markup.

A layout file is the physical file residing in the file system as opposed to the page templates, based on this layout file. You work with page templates in the Sitefinity CMS backend   .

A layout file resides in the file system – in your Sitefinity project – and has links to all the CSS and JavaScript files needed by the pages, based on page templates, and other related files to the website. In this layout file you structurally divide the website pages into sections.

Depending on which mode you are working in, the layout files can be:

  • .cshtml layout files (MVC only templates)
  • .master file or .ascx page template files (hybrid and Web Forms only templates) -> when you base page template son the master file(s), they are stored in the database but are not physical files; do not need to map them to files like with MVC templates

RECOMMENDATION:  Working in MVC mode is the recommended way to work in Sitefinity CMS, especially for new projects. Development process is optimized and modification of your website functionality and appearance – quick and easy.

Generate MVC page templates from layout files

Once Sitefinity CMS detects there is a new .cshtml layout file in the respective project folder, for example, ~/ResourcePackages/YourPackageName/Mvc/Views/Layouts , upon application restart, it automatically generates a new page template, based on the layout file. At a later point in time, you can modify the page template to add grid and layout widgets.

If you have a package that includes multiple layout files, corresponding page templates are automatically created for each layout file in Sitefinity CMS under Design > Page templates.

If you delete the generated page template, it is not generated again, unless you delete and then re-add the layout file while you have the Sitefinity CMS instance up and running as a process. Another option is to manually create a pure MVC page template in Sitefinity CMS that follows the naming convention. For example, if you have a ~/MVC/Views/Layouts/MyMvcLayout.chtml file, the Developer name of the template must be MyMvcLayout. If the file is inside a package named MyPackage, ~/ResourcePackages/YourPackageName/MVC/Views/Layouts/MyMvcLayout.chtml the Developer name of the template must be MyPackage.MyMvcLayout.

If you delete the layout file, the generated page template continues to exist, but is not based on anything. Later, if you add a layout file that matches the naming convention for that template, additional template is not generated and the previous template uses this layout again.

For more information about how page templates and layout files are associated to each other, see Map page templates to layout files.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?