For developers: Create MVC page templates based on layout files
Sitefinity CMS provides you with a few options for adding MVC page templates.
IMPORTANT: When deciding where to create or add your template, consider the factors for resolving views, as well as the naming conventions for new template files. For more information, see Priorities for resolving views.
The recommended way to create page templates is to use packages. Packages are suitable for cases when you want to base your templates on frontend frameworks, for example, Bootstrap. To create a page template in such cases add a layout file inside folder ~/ResourcePackages/YourPackageName/Mvc/Views/Layouts, following the naming conventions. For more information about packages, see Overview: Resource packages.
NOTE: If the ResourcePackages
folder does not contain any packages, the widget templates are loaded from the MVC folder of SitefinityWebApp, in case this folder contains files with names that follow the naming convention. Templates from the widgets' assemblies have the lowest loading priority, templates in the MVC folder of SitefinityWebApp have higher priority, and templates from a package have the highest loading priority.
Another option to add a new layout file is inside the ~/MVC/Views/Layouts
folder, Sitefinity CMS generates a pure MVC page template with a title matching the layout file name. This way you can immediately start using this template that is based on the layout file.
NOTE: The template and the layout file are connected via the naming convention. If you rename the layout file, the relationship with the page template breaks and a new page template is created.
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 that follows the naming convention. For example, if you have a MyMvcLayout.chtml
file, the template must be titled MyMvcLayout. If the file is inside a package named MyPackage, the template must be named 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.
If you have a package that includes multiple layouts, corresponding templates are automatically created for each of them.
NOTE: The 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. Once Sitefinity CMS detects there is a new .cshtml layout file in the respective folder, for example, ~/MVC/Views/Layouts/ folder, it creates a new page template, based on the layout file. You can later on add widgets on the page template and save it. However, when creating a new layout file that holds a Razor layout reference to the original layout file, the newly created page template in Sitefinity CMS does not inherit the widgets that you added to the original page template.