Tags

, ,

One of Sitecore’s greatest feats is the ability to organize multiple websites in one single Content Management System. End users could achieve a significant productivity gain by this. But it also allows content editors to share content over multiple sites. This results in much flexibility, and offers users a much broader content strategy.

Content Sharing could be achieved with a number of different structures:

  • Sharing pages
  • Sharing a single global data folder
  • Sharing multiple local data folders

Sharing pages
First let’s discuss the sharing of pages. Image you have two sites. Both sites contain products, which are located under a Products item. The products in Website 1 are different than in Website 2, but there is the wish to share these products over multiple sites.

Multisite tree 1

Now we have to decide how you show items from another site. It is possible to show the products under the site where they originated, or to show the items under the site from where they were requested. This distinction is made with the setting “SiteResolving” in the web.config, as explained by Brian Pedersen. When turned to “true”, the URL returned from the Sitecore.Links.LinkManager will look like this:

www.website2.com/products/product2

When turned to “false”, the URL will look like this:

www.website1.com/sitecore/content/website2/products/product2

The problem with the first structure is that you will be redirected to another website, and this may not be desirable. But the problem with the latter case is that an item from another website is resolved directly under the current website. In many cases, different sites haves different designs and layout, and these are also transported directly. For the user, it is confusing when he is navigated to a page under website 1, that has a totally different design and layout, namely that of website 2.

Shared content
This problem could be solved by separating the data aspect from the presentation aspect. One way to achieve this is by using Wildcards.
First, we add a folder where we store all of our products. In this case we place this folder under Shared Content, because we want to share our content. But in contrast to our last example, these product items only consist of fields (like Title, Text, Introduction, and Date), and they do not contain any sublayouts with which to render these fields. These sublayouts and renderings are concentrated on one single item, at the place where we want to show our products on the website. This item has be named “*” in order to work as a wildcard, but we have used its display name to show it as “* [Product Detail]” in the Sitecore tree.

Shared Content

Now whenever a request is made to “www.website1.com/products/product2”, the part “product2” of the URL takes the place of the wildcard, and could be resolved using a custom Sitecore pipeline. (How to build this pipeline is not the subject of this article)

We will have to join together the wildcard and the products. For this, we could use a “junction item”. We should make a “Junction” template, on which we could select a folder in the Shared Content section and a wildcard item. This junction item could then be used to tell the custom ItemResolver pipeline where to look for an appropriate item when hitting a certain wildcard item.

string query = string.Format("./*[@@name='{0}']", requestedItemName);
Item requestedItem = productsFolder.Axes.SelectSingleItem(query);

Sitecore Local settings

The downside to this approach is that we now have one large pile of products. We don’t know from which website the product originated. And we don’t have the possibility to determine whether a certain product is shared or not: they are all shared. So we also have to look at another possibility to achieve this and make the shared content more manageable.

Local content
In order to make shared content more manageable, we have to create a Local Content folder under each website, and all the local product in a Products folder. Now we still have the separation between data and presentation, but we are still inside the context of the current site. The resolving of the wildcard for local products will be unchanged. We only have to set the data folder of the Products to the local products folder.

Sitecore Shared Content Local

Now for shared content, we have to make a few extensions. On the one hand we want to determine from which sites we want to receive shared content. On the other hand we want to determine which content from the source site will be shared at all. Some content should be able to stay local.

First we extend the Product template with a checkbox with which we could determine whether the product should be able to appear on other websites. Then we extend the before-mentioned Junction item. For each site in the installation, we have to add a field where we can select the local content folder of that site. So if the item could not be resolved from the Local products, try to resolve it from shared product folders instead:

foreach (Item sharedProductsFolder in sharedProductsFolders)
{
 string query = string.Format("./*[@IsShared='1' AND @@name='{0}']", requestedItemName);
 Item requestedItem = productsFolder.Axes.SelectSingleItem(query);
 if (requestedItem != null)
 {
 break;
 }
}

The way URLs to Shared Content items are resolved is extremely important for a desirable implementation of a multisite installation of Sitecore. In the next article, we will explain how URLs to Shared Content could be constructed and resolved.

Advertisements