For the complete documentation index, see llms.txt. This page is also available as Markdown.

Creating a Layout Template

The previous articles covered how to create a Document Type and its corresponding Template. To build a site with Home, News, and Contact Us pages, create a Document Type with a corresponding Template for each.

You may end up copying the same HTML code into each of these templates, which can be time-consuming and repetitive. In such scenario, you might want to consider creating a new layout template.

To create a new layout template:

  1. Go to Settings.

  2. Select the ... next to the Templates folder. Alternatively, click + to open a blank template.

  3. Click Create. A template opens up in the content editor.

  4. Enter a Name for the layout template. Let's call it Layout.

    Layout Template
  5. Click Save.

Using the Layout Template

To use the layout template:

  1. Go to Settings.

  2. Expand the Templates folder from the Templating section.

  3. Open the Homepage template.

  4. Select Layout template: No layout. The Layout template dialog opens on the right-side of the browser.

  5. Select the template called Layout.

  6. Click Choose. The Razor code section is updated from Layout = null; to Layout = "Layout.cshtml";

    Adding Layout Template to HomePage
  7. Click Save.

Updating Templates With the New Layout Template

Let's move the parts of the HTML template that are common across all templates into the Layout. It might be slightly different for different websites. You'll need to consider if all pages contain a <div id="main"> section so that you can update it in the layout.

To update templates with the new layout template, follow these steps:

  1. Go to Settings.

  2. Expand the Templates folder from the Templating section.

  3. Navigate to the Homepage template.

  4. Cut everything from the <!DOCTYPE HTML> (around line 8) to the end of the </div> tag (around line 44). It is the header and navigation of the site to the layout template.

    Header and navigation tags selected in the HomePage template
  5. Click Save.

  6. Go to the Layout template and paste this HTML markup after the closing curly brace (around line 7).

  7. Add @RenderBody() at the end of the markup. This will tell Umbraco to insert the child template's content.

    Adding renderbody in the Layout template
  8. Click Save.

  9. Repeat the same process for the footer content:

    • Go to the Homepage template.

    • Cut everything from the <!-- Footer --> tag (around line 109) to the end of the </html> tag (around line 123).

    • Click Save.

    • Go to the Layout template.

    • Paste this HTML markup after the @RenderBody() field.

      End of the Layout template
  10. Click Save.

Now, a lot of work is done. Refresh the localhost page, nothing should change. If you have a compilation error you have perhaps mistyped @RenderBody().

If you are missing any content such as header or footer, ensure that the templates matches the following:

See the entire file: Layout Template
See the entire file: HomePage Template

Last updated

Was this helpful?