Bind data to your site configuration in Sitecore

Whenever I have a Sitecore website that defines multiple site instances I find I will at some point have to define data specific to each of those instances.

Site instances are defined in the config file under the <sites> node. They define some default parameters (virtualFolder or hostName for instance), all of which are described in the configuration file so I won’t go into any detail about them. I do want however to reference three of them, specifically, name, language and startItem. These three because they are most commonly used to bind data to a site instance as far as I’ve seen.

The problem with any of these three is that I would have to match them one by one to some other reference. I Would have to loop through all site instances and check the parameter against that reference until I find what I am looking for. Say for instance, I have a couple of items defined in Sitecore that represent countries and there is a 1 to 1 mapping between country and sites, but these countries are defined as content items (not underneath the home root item of a site). How would I then map the country to the site? There are a lot of options here but I think none better than doing something like this:

    public static class ESiteInfo
        public static string GetCountryPath(this SiteInfo info)
            string result = info.Properties["CountryPath"];
            return string.IsNullOrEmpty(result) ? result : result.Trim();
    <site name="americas" CountryPath="sitecore/content/Management/Countries/USA" rootPath startItem ... />

Leave a Reply