2

I have a multisite solution with two sites, xyz.com and abc.com. For a given appsetting variable I want to have different values. Is it something which is possible out of the box in Sitecore?

The patch file will overwrite the variable and hence cannot use it.

5

It can be done using two different techniques:

Technique 1

Inside the site tag you can add your custom attribute like the below code:

<site patch:before="*[@name='website']"
           ....
                  customSetting="XXX"
            />

You can patch this file for multiple sites and you can get this value like this Context.Site.Properties["customSetting"]

Technique 2

You can add one field in the SiteRoot template and get the value from that field.

Enter image description here

  • thanks, i was trying to use targethostname the same way but didn't realize that i can use a custom field as well. will try this one. – rdhaundiyal May 29 at 6:39
2

When you say that you have a multisite solution, I understand you have multiple sites defined in the Sitecore <sites> section like this:

<site
    name="xyz"
    hostName="xyz.com"
    rootPath="/sitecore/content/site-a"
    startItem="/home"
    />
<site
    name="abc"
    hostName="abc.com"
    rootPath="/sitecore/content/site-b"
    startItem="/home"
    />

You can add any custom properties to every site definition like:

<site
    name="xyz"
    hostName="xyz.com"
    rootPath="/sitecore/content/site-a"
    startItem="/home"
    myCustomValue="custom value XYZ"
    />
<site
    name="abc"
    hostName="abc.com"
    rootPath="/sitecore/content/site-b"
    startItem="/home"
    myCustomValue="custom value ABC"
    />

And then read it in the code

    var value = Context.Site.Properties["myCustomValue"];
2

Instead of AppSetting you can keep such site specific values in Sitecore. To add settings to the site, modules should define templates which can be added as base templates to the site root item for the project layer module, or add settings items inside the site hierarchy.

For example, the Feature/Accounts module defines an AccountsSettings template which is assigned to the Site Root template in the Project/Habitat module.

The module uses the site hierarchy to find the settings items for the module.

public virtual Item GetAccountsSettingsItem(Item contextItem)
{
    Item item = null;

    if (contextItem != null)
    {
        item = contextItem.GetAncestorOrSelfOfTemplate(Templates.AccountsSettings.ID);
    }
    item = item ?? Context.Site.GetContextItem(Templates.AccountsSettings.ID);

    return item;
}
  • Yes, I was doing that earlier but that has its own issue, when we restore db to lower environment that get copies to lower environment as well which i want to avoid. – rdhaundiyal May 29 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.