Map page templates to layout files

A layout file resides in your Sitefinity CMS project and has links to all CSS and JavaScript files needed on the pages based on templates linked to this layout file. You can add as much placeholders in your layout file as you want, sometimes even a single one works since you may want to create a diverse set of page templates, based on it. When you base MVC page templates on a layout file, in Sitefinity CMS backend, you add all relevant structural sections to the template itself. These include header, navigation, main, footer, and so on. Of course, you can do that in the layout file itself but that may later pose problems if you want to modify the layout file since you cannot move the elements or rename them.

An MVC page template and a layout file are associated to each other via the naming convention. If you rename the layout file, the relationship with the page template breaks and a new page template is generated. Similarly, if you delete a layout file, the page template continues to exist and function, you can configure and edit the grid and content widgets on pages, based on this template but you cannot edit the layout file itself. This means you cannot edit the placeholders, markup, and links. To do so, you need to map the page template to a layout file. In addition, if this layout file had hardcoded links, or you need to add an extra class or meta tag, you cannot do that until you create a new layout file and map the page template to it in accordance with the naming conventions. For more information, see Naming conventions.

On the other hand, if you delete the page template, associated to a layout file, you can later create a new template and map it to the layout file, so that you can work with it and use it in the file system.

The following sections describe in detail these scenarios, which are uncommon use cases:

  • Create a new layout file
  • Create an MVC page template and map it to a layout file
  • Map a layout file to an existing MVC page template

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?