1

We are currently working on Sitecore 10.3 (SXA enabled) Headless + NextJS. According to the requirements, we need to add new fields in the Site Settings. To read these new fields, we have overridden the configuration.getAppConfiguration pipeline and the GetConfigurationFromItems processor (Attached screenshot of the code).

<pipelines>
          <group groupName="javaScriptServices">
            <pipelines>
              <configuration.getAppConfiguration>
                <processor type="XXX.Foundation.SiteSettings.Pipelines.JssConfigurationItem, XXX.Foundation.SiteSettings" 
                           patch:instead="processor[@type='Sitecore.XA.JSS.Foundation.Multisite.Pipelines.GetAppConfiguration.GetConfigurationFromItems, Sitecore.XA.JSS.Foundation.Multisite']"
                           resolve="true"/>
              </configuration.getAppConfiguration>
            </pipelines>
          </group>
        </pipelines>

However, when attempting to read the same using Sitecore.Context.Site.Properties["gdprVersion"] it returns null. Surprisingly, we are also getting null for existing fields like "dictionaryPath," etc. enter image description here Can anyone help us identify if we are missing anything here?

2 Answers 2

0

As you mentioned we are also getting null for existing fields, could you check if your sxa site is resolving correctly?

You can refer to this blog : https://pratiksatikunvar.wordpress.com/2017/09/11/how-your-sxa-site-gets-resolved/

public void Process(GetConfigurationArgs args)
  {
    IEnumerable<SiteInfo> mySites = ServiceLocator.ServiceProvider.GetService<ISiteInfoResolver>().Sites;
    Database currentDatabase = GetCurrentDatabase();
    foreach (SiteInfo siteInfo in mySites)
    {
      Item item1 = currentDatabase.GetItem(siteInfo.RootPath, Language.Parse(siteInfo.Language));
      if (item1.IsInSxaContext() && item1.InheritsFrom(Sitecore.XA.JSS.Foundation.Multisite.Templates.JSSSite.ID))
      {
        Item item2 = item1.FirstChildInheritingFrom(Sitecore.XA.JSS.Foundation.Multisite.Templates.JSSSettings.ID);
   
        if (item2 != null)
        {
          args.AppAttributes.Add(new AppAttributes()
            {
              "importDatabase", item2[Sitecore.XA.JSS.Foundation.Multisite.Templates.JSSSettings.Fields.ImportDatabase]
            },
            ...
            ...
            ...
            );
        }
      }
    }
  }
0

You need to override the existing SXA pipeline to be able to add the custom setting. Below is the code snippet.

public class JssConfigurationItem
{
    protected IMultisiteContext MultisiteContext { get; } = ServiceLocator.ServiceProvider.GetService<IMultisiteContext>();

    public void Process(GetConfigurationArgs args)
    {
        IEnumerable<SiteInfo> sites = ServiceLocator.ServiceProvider.GetService<ISiteInfoResolver>().Sites;
        Database currentDatabase = GetCurrentDatabase();
        foreach (SiteInfo siteInfo in sites)
        {
            Item obj1 = currentDatabase.GetItem(siteInfo.RootPath, Language.Parse(siteInfo.Language));
            if (obj1.IsInSxaContext() && obj1.InheritsFrom(Sitecore.XA.JSS.Foundation.Multisite.Templates.JSSSite.ID))
            {
                Item obj2 = obj1.FirstChildInheritingFrom(Sitecore.XA.JSS.Foundation.Multisite.Templates.JSSSettings.ID);
                Item tenantItem = MultisiteContext.GetTenantItem(obj1);
                if (obj2 != null && tenantItem != null)
                {
                    args.AppAttributes.Add(new AppAttributes()
                    {
                          {
                            "name",
                            obj2[Sitecore.XA.JSS.Foundation.Multisite.Templates.JSSSettings.Fields.AppName]
                          },
                          {
                            "sitecorePath",
                            obj1.Paths.FullPath
                          },
                          
                          // ADD YOURS HERE
                    }
                }
            }
        }
    }
}

protected virtual Database GetCurrentDatabase()
{
    string name = string.Empty;
    foreach (SiteProvider provider in (ProviderCollection)ServiceLocator.ServiceProvider.GetService<ProviderHelper<SiteProvider, SiteProviderCollection>>().Providers)
    {
        if (provider is ISxaDatabaseSiteProvider)
        {
            name = (provider as ISxaDatabaseSiteProvider).Database;
            break;
        }
    }
    return Factory.GetDatabase(name, false);
}

protected virtual string GetTargetItemPath(Item item, ID fieldId)
{
    Field field = item.Fields[fieldId];
    ID result;
    if (field != null && ID.TryParse(field.Value, out result))
    {
        Item obj = item.Database.GetItem(result);
        if (obj != null)
            return obj.Paths.FullPath;
    }
    return string.Empty;
}

To read it from the Site definition, you can use the below code

var internalServerError = Context.Site.Properties["internalServerError"];

For more details you may refer to this link.

SITECORE – EXTEND JSS CONFIGURATION SETTINGS

Hope this helps.

3
  • I am using the same code, but this also given me null Commented Apr 10 at 11:15
  • @HariPrasadKotha Did you add your setting value in the other properties? Commented Apr 10 at 11:17
  • I have added this custom field in "/sitecore/content/<Tenant>/<Site>/Settings" Commented Apr 10 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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