Kentico CMS 6.0 Developer's Guide

Managing page layouts

Managing page layouts

Previous topic Next topic Mail us feedback on this topic!  

Managing page layouts

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a page layout.

 

private void CreateLayout()
{
    // Create new layout object
    LayoutInfo newLayout = new LayoutInfo();
 
    // Set the properties
    newLayout.LayoutDisplayName = "My new layout";
    newLayout.LayoutCodeName = "MyNewLayout";
    newLayout.LayoutDescription = "This is layout created by API Example";

   newLayout.LayoutCode = "<cc1:CMSWebPartZone ID=\"zoneLeft\" runat=\"server\" />";

 
    // Save the layout
    LayoutInfoProvider.SetLayoutInfo(newLayout);
}

 

The following example gets and updates a page layout.

 

private bool GetAndUpdateLayout()
{
    // Get the layout
    LayoutInfo updateLayout = LayoutInfoProvider.GetLayoutInfo("MyNewLayout");
    if (updateLayout != null)
    {
        // Update the properties
        updateLayout.LayoutDisplayName = updateLayout.LayoutDisplayName.ToLower();
 
        // Save the changes
        LayoutInfoProvider.SetLayoutInfo(updateLayout);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates page layouts.

 

private bool GetAndBulkUpdateLayouts()
{
    // Prepare the parameters
    string where = "LayoutCodeName LIKE N'MyNewLayout%'";
 
    // Get the data
    DataSet layouts = LayoutInfoProvider.GetLayouts(where, null);
    if (!DataHelper.DataSourceIsEmpty(layouts))
    {
        // Loop through the individual items
        foreach (DataRow layoutDr in layouts.Tables[0].Rows)
        {
            // Create object from DataRow
            LayoutInfo modifyLayout = new LayoutInfo(layoutDr);

 
          // Update the properties
           modifyLayout.LayoutDisplayName = modifyLayout.LayoutDisplayName.ToUpper();

 
            // Save the changes
            LayoutInfoProvider.SetLayoutInfo(modifyLayout);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a page layout.

 

private bool DeleteLayout()
{
    // Get the layout
    LayoutInfo deleteLayout = LayoutInfoProvider.GetLayoutInfo("MyNewLayout");
 
    // Delete the layout
    LayoutInfoProvider.DeleteLayoutInfo(deleteLayout);
 
    return (deleteLayout != null);
}