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.

In Sitefinity CMS, the layout files have .cshtml layout file extension.

MVC layout file location and naming conventions

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.

.NET Core layout file location and naming conventions

The .NET Core pages are based on templates that are stored in the Renderer application. The .NET Core templates are MVC layout files, stored on the file system. If a page is based on one of these layout files, the Renderer will be able to render the page.

To create a base layout for all of your pages, you can leverage the power of Layout in ASP.NET Core. The layout files that are located in the Renderer’s Views/Shared folder are scanned and displayed in the template selector when you create a new page. However, not all of the layout files are listed there. They are filtered by their name and only the ones that contain the words Template or Layout are displayed.

NOTE: Every layout file must have a section named Scripts.

Out-of-the-box Sitefinity ASP.NET Core Renderer comes with a blank template called Default that you can select in the template selector. This layout file references Bootstrap5 CSS framework. The default Section widget templates also contain the Bootstrap5 grid system markup.

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?