0

I have a Sitecore 9.2 SXA solution currently holding five Sites. Let's say

  • Tenant
    • Corporate
      • Site1
      • Site2
      • Shared
      • Site3
      • Site4

All Sites are accessible, except for Shared, where there's a source of items under the premise they could be accessible through all other sites. Let's say

  • Shared
    • Projects
      • Project1
      • Project1

The client requirement is that those Projects could be accessed by any of the public sites. I resolved that by using a wildcard and a custom Item Resolver. So, Site1 has something similar to this:

  • Site1
    • Projects
      • (*)
<code>

    {
        public class WildcardItemResolver : HttpRequestProcessor
        {
            public override void Process(HttpRequestArgs args)
            {
                
                var resolvedItem = ResolveItem(args);
                if (resolvedItem != null)
                {
                    Context.Item = resolvedItem;
                }
                return;
            }
        }

        private Item ResolveItem(HttpRequestArgs args)
        {
            var path = MainUtil.DecodeName(args.Url.ItemPath);
            var itemName = path.Split('/').Last();
            var masterRootItem = "content/Tenant/Corporate/Shared/Projects"

            SitecoreIndexableItem indexableItem = new SitecoreIndexableItem(Context.Item);
            using (var searchContext = ContentSearchManager.GetIndex(indexableItem).CreateSearchContext())
            {
                var predicate = PredicateBuilder.True<BaseSearchResultItem>();
                predicate = predicate.And(item => item.IsLatestVersion &&
                    item.Templates.Contains(Context.Item.TemplateID.Guid) &&
                    item.Path.Contains(masterRootItem.Paths.Path));

                IQueryable<SearchResultItem> query = searchContext
                    .GetQueryable<BaseSearchResultItem>()
                    .Where(i => i.Name.Contains(itemName))
                    .Filter(predicate);

                var searchResults = query.GetResults();
                return searchResults.Hits.FirstOrDefault().Document.GetItem();
            }
        }
    }

</code>

This approach works just fine and when requests hit site1/projects/Project1 or site3/projects/Project1, the ItemResolver quicks in, finds the appropriated item and sets it as the Context.Item.

The problem is, the Presentation also needs to be changed. Every Site has its own Layout, Presentation and Theme and once the item from Shared is resolved, the SXA Presentation also becomes the one associated with Shared.

I need to programmatically change the Context presentation, to the one used by the appropriate site.

Ideas?

3
  • Hi Eduardo, did you thought about changing the approach to achieve this? I think this item resolver can be quite problematic. Have a look at SXA Delegated Areas: doc.sitecore.com/en/users/sxa/17/… Jul 7 at 6:54
  • Hi @MiguelMinoldo. Coincidentally...we're taking this approach exactly because of SXA Delegated Areas. That was the original setup. It worked fine at first but as the content grew in size, we started experiencing problems. Adding new items in the master repo, started creating duplicated clones in the other sites. Also, even small changes in the source item took an unbearable amount of time to complete, even 504'ing the server. Sitecore support was contacted, could not produce a satisfactory solution and advised for the wildcards. And here I am :-)
    – Eduardo
    Jul 7 at 15:10
  • Oh.. Got it.. Thanks for sharing! You would also check the site resolver, or switching the context site may help, but again I'm a bit concerned this approach can lead to some unexpected behavior. Jul 7 at 15:52

Your Answer

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

Browse other questions tagged or ask your own question.