SharePoint 2013 WCM Advanced Cookbook
上QQ阅读APP看书,第一时间看更新

Creating a custom composed look

Composed looks are stored as items in the _catalogs/design list within each SharePoint site. They can specify the master page, color palette, font scheme, background image, and display order in relation to other composed looks.

How to do it...

Follow these steps to create a custom composed look:

  1. Navigate to the site in your preferred web browser.
  2. Select Site settings from the Settings menu.
  3. Select Composed looks in the Web Designer Galleries section.
    How to do it...
  4. Click on New Item to create a new composed look item in the list.
  5. Enter the name for the composed look in both the Title and Name fields.
  6. Enter the URLs to the master page, color palette, background image, and font scheme files in both the Web Address and Description fields for each section.
  7. Enter the Display Order.
  8. Click on Save.

How it works...

Composed looks are simply stored as items in the _catalogs/design list. When a composed look is applied to a site the items specified in the composed look are used to create a SPTheme object that then gets applied to the SPWeb object representing the site. If no background image is specified, none will be applied when using this composed look. If no font scheme is specified, the default SharePointPersonality.spfont font scheme will be applied when using this composed look.

Lastly, the Display Order option is used to sort the available composed looks when choosing which composed look to apply to a site. Have a look at the following screenshot:

How it works...

There's more...

A composed look can be created with PowerShell or code using the server-side object model.

Creating a custom composed look using PowerShell

Follow these steps to create a custom composed look using PowerShell:

  1. Get the site using the Get-SPWeb Cmdlet:
    $web = Get-SPWeb http://sharepoint/site
    
  2. Get the SPList object representing the _catalogs/design list from the SPWeb object:
    $list = $web.Lists["Composed Looks"]
    
  3. Add a new SPListItem to the Items collection of the SPList object:
    $item = $list.Items.Add()
    
  4. Assign the values to each of the properties of the SPListItem object:
    $item["Title"] = "PowerShell"
    
    $item["Name"] = "PowerShell"
    
    $item["Master Page URL"] = 
    "/_catalogs/masterpages/seattle.master"
    
    $item["Theme URL"] = "/_catalogs/theme/15/palette005.spcolor"
    
    $item["Image URL"] = "/_layouts/15/images/image_bg005.jpg"
    
    $item["Font Scheme URL"] = 
    "/_catalogs/theme/15/fontscheme003.spfont"
    $item["Display Order"] = "200"
  5. Use the Update method on SPList to update the Items collection:
    $item.Update()
    
  6. Use the Dispose method to discard the SPWeb object:
    $web.Dispose()
    

Creating a custom composed look with code using the server-side object model

Follow these steps to create a custom composed look with code using the server-side object model:

  1. Open the site collection containing the site in a using statement:
    using (var site = new SPSite("http://sharepoint/site"))
  2. Open the site in a using statement:
    using (var web = site.OpenWeb())
  3. Get the SPList object representing the _catalogs/design list from the SPWeb object:
    var list = web.Lists["Composed Looks"];
  4. Add a new SPListItem to the Items collection of the SPList object:
    var item = list.Items.Add();
  5. Assign the values to each of the properties of the SPListItem object:
    item["Title"] = "PowerShell";
    
    item["Name"] = "PowerShell";
    
    item["Master Page URL"] = 
      "/_catalogs/masterpages/seattle.master";
    
    item["Theme URL"] = 
      "/_catalogs/theme/15/palette005.spcolor";
    
    item["Image URL"] = "/_layouts/15/images/image_bg005.jpg";
    item["Font Scheme URL"] = "/_catalogs/theme/15/fontscheme003.spfont";
    
    item["Display Order"] = "200";
  6. Use the Update method on the SPList object to update the Items collection:
    item.Update();

See also