allBlogsList

Sitecore Site Settings

As long as I have been a developer creating dynamic based websites, I have used some form of storage to contain the more general settings of a site.  Developing in Sitecore is no exception, and its ability to expand to multiple site solutions as well as various languages demands it. Within Sitecore you will want to create a Site Settings item that lives in the data section of your site.  A specific name is not required, however just naming it "Site Settings" is generally good enough.  The fields should specifically be global elements of the site.  Also consider globalization and identify fields that may need to be shared to cut down on future maintenance. Here is a list of possible fields to live in you Site Settings item:

  1. Site logo / header image.
  2. Navigation.  If your navigation structure is a separate data structure from the content tree then this can be a path to your navigation parent item.  If your navigation is content tree based, you could set up excludes here to remove specific items or templates from your navigation.
  3. Defaults.  The most common fields to fall under this area would be browser titles and meta data.  This will allow all pages to at least show the defaults if author does not fill out the information on a specific page.
  4. Footer text.

Once you have your Site Settings item in place you will need to be able to reference it.  For this you should create a reference to it in the configs.  Specifically assign the Site Settings item guid to the site tag.  This approach will allow one Site Settings item per defined site. Below is a common site definition patch including our Site Settings reference:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <sites>
      <site name="mysite" patch:before="site[@name='website']"
	    virtualFolder="/"
	    physicalFolder="/"
            rootPath="/sitecore/content"
            startItem="/mysite/"
            database="master"
            domain="extranet"
            allowDebug="true"
            cacheHtml="true"
            htmlCacheSize="10MB"
            registryCacheSize="0"
            viewStateCacheSize="0"
            xslCacheSize="5MB"
            filteredItemsCacheSize="2MB"
            enablePreview="true"
            enableWebEdit="true"
            enableDebugger="true"
            disableClientData="false"
            siteSettingsItemID="{4F8D177A-216E-4265-7D73-4G5B46CF5EF9}" />
    </sites>
  </sitecore>
</configuration>

Our Site Settings item is reference with the value of siteSettingsItemID. Finally for easy access, place the call to your Site Settings item in a class:

public static Item GetSettingsItem()
        {
            string itemID = Context.Site.SiteInfo.Properties["siteSettingsItemID"];
            if (!String.IsNullOrEmpty(itemID))
            {
                Item settingsItem = Sitecore.Context.Database.GetItem(ID.Parse(itemID));
                if (settingsItem != null)
                {
                    return settingsItem;
                }
            }

			return null;
        }