Varying content and presentation by host name in S

2019-07-24 08:15发布

Scenario: A section of the content tree is the home item for a site that runs under two host names (www.site1.com and www.site2.com

The purpose of the two host names is to differentiate between two target countries that are served with the same content, and the same organisation (marketing department, web editor etc.)

The content is, of course, identical across the two host names.

Except....

In a couple of places we need some small differences. A contact email, for instance, or a legal notice (these are both just Sitecore content). In other places we may wish to be able to change a presentation component for an item based on which host context it's in. We may wish to do this across all items from a specific template.

To complicate matters, the site is already cloned from another site (www.siteA.com), which is the source of several clones (some translated) for different countries. This is to enable us to push new items/content changes/features to our subsidiary companies. So all templates and presentation components are already shared across lots of host contexts and lots of portions of the content tree.

Is there any Sitecore functionality that would make this possible/simple - or do we need to code context testing into our presentation components (presumably alongside some configuration items within Sitecore to avoid hardcoding values)?

1条回答
可以哭但决不认输i
2楼-- · 2019-07-24 09:01

Great question. This is a long-shot, but it may work:

Why don't you create a new device for Site2 and in the cases where Site2 presentation data needs to change, configure the presentation settings for the Site2 device. If not, don't set them and the Default device will render the content. The hard part here will be configuring how the device will resolve. Maybe you can create a custom device resolver in the <httpRequestBegin> pipeline:

<processor type="Sitecore.Pipelines.HttpRequest.BeginDiagnostics, Sitecore.Kernel"/>
<!--<processor type="Sitecore.Pipelines.HttpRequest.DeviceResolver, Sitecore.Kernel"/>-->
<processor type="YourProject.Pipelines.HttpRequest.DeviceResolver, YourProject"/>
<processor type="Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel"/>

In your processor you can look at the host to determine which to use.

You can also define the Site2 device on a new <site ... /> node as Paul mentions below. Something like this:

<site name="site1" hostName="site1.com" rootPath="/sitecore/content" startItem="/home" ... />
<site name="site2" hostName="site1.com" device="Site2" rootPath="/sitecore/content" startItem="/home" ... />

Both Site1 and Site2 point to the same parts of the tree, they just use different devices.

查看更多
登录 后发表回答