---
title: Page layouts
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

### Setting a custom layout for a page template

```csharp

// Gets the page template
PageTemplateInfo pageTemplate = PageTemplateInfoProvider.GetPageTemplateInfo("NewTemplate");
if (pageTemplate != null)
{
    // Sets the template's layout type to ASCX
    pageTemplate.PageTemplateLayoutType = LayoutTypeEnum.Ascx;

    // Sets the custom layout code of the template
    pageTemplate.PageTemplateLayout = "<cms:CMSWebPartZone ZoneID=\"zoneExample\" runat=\"server\" />";

    // Saves the template changes to the database
    PageTemplateInfoProvider.SetPageTemplateInfo(pageTemplate);
}

```

[> Back to list of examples](#toc)

### Creating a shared page layout

```csharp

// Creates a new layout object
LayoutInfo newLayout = new LayoutInfo();

// Sets the layout properties
newLayout.LayoutDisplayName = "New layout";
newLayout.LayoutCodeName = "NewLayout";
newLayout.LayoutDescription = "This is a layout created by an API example";
newLayout.LayoutType = LayoutTypeEnum.Ascx;
newLayout.LayoutCode = "<cms:CMSWebPartZone ZoneID=\"zoneA\" runat=\"server\" />";

// Saves the layout to the database
LayoutInfoProvider.SetLayoutInfo(newLayout);

```

[> Back to list of examples](#toc)

### Updating a shared page layout

```csharp

// Gets the layout
LayoutInfo updateLayout = LayoutInfoProvider.GetLayoutInfo("NewLayout");
if (updateLayout != null)
{
    // Adds another web part zone into the layout code
    updateLayout.LayoutCode += "<cms:CMSWebPartZone ZoneID=\"zoneB\" runat=\"server\" />";

    // Saves the changes to the database
    LayoutInfoProvider.SetLayoutInfo(updateLayout);
}

```

[> Back to list of examples](#toc)

### Updating multiple shared page layouts

```csharp

// Gets all shared page layouts whose code name starts with 'NewLayout'
var layouts = LayoutInfoProvider.GetLayouts().WhereStartsWith("LayoutCodeName", "NewLayout");

// Loops through individual layouts
foreach (LayoutInfo layout in layouts)
{               
    // Updates the layout properties
    layout.LayoutDisplayName = layout.LayoutDisplayName.ToUpper();

    // Saves the changes to the database
    LayoutInfoProvider.SetLayoutInfo(layout);
}

```

[> Back to list of examples](#toc)

### Assigning a shared page layout to a page template

```csharp

// Gets the page template
PageTemplateInfo pageTemplate = PageTemplateInfoProvider.GetPageTemplateInfo("NewTemplate");

// Gets the layout
LayoutInfo sharedLayout = LayoutInfoProvider.GetLayoutInfo("NewLayout");

if ((pageTemplate != null) && (sharedLayout != null))
{
    // Assigns the page layout to the template
    pageTemplate.LayoutID = sharedLayout.LayoutId;              

    // Saves the template changes to the database
    PageTemplateInfoProvider.SetPageTemplateInfo(pageTemplate);
}

```

[> Back to list of examples](#toc)

### Deleting a shared page layout

```csharp

// Gets the layout
LayoutInfo deleteLayout = LayoutInfoProvider.GetLayoutInfo("NewLayout");

if (deleteLayout != null)
{
    // Deletes the layout
    LayoutInfoProvider.DeleteLayoutInfo(deleteLayout);
}

```

[> Back to list of examples](#toc)
