0

As we all know with SXA version 1.8 it is possible to insert components inside a rendering variant definition.

Go to 6. - Components: https://doc.sitecore.com/developers/sxa/18/sitecore-experience-accelerator/en/create-a-rendering-variant.html

In my particular example I want to add the breadcrumb component to a search results rendering variant, but following official documentation steps it doesn't work. This is the section when I'm adding the breadcrumb component:

enter image description here

And this is on the actual page when loading it, is stuck:

enter image description here

I've also tried to define a new placeholder setting under /sitecore/content/Tenant/Site1/Presentation/Placeholder Settings and then using this placeholder key on the breadcrumb component under the rendering variant. This doesn't work as well...

Is someone having experience with something like this and willing to help?

Thank you

8
  • What do you mean by "it doesn't work"? Can you add some screenshots and more clarification to your question? Commented Jan 15, 2019 at 16:40
  • 1
    @EmanuelPopescu I've reproduced this error (and the full stack trace is available in the log.. ) and I think the RenderComponentField pipeline processor doesn't work for the search results variant since search results are requested in an api call, which would be running in a different context. I suspect this isn't working for any variants that are being requested through an api call. Maybe worth a shot raising this with Sitecore Support Commented Jan 17, 2019 at 16:17
  • 1
    @Jen it didnt worked ootb. I've created a an NVelocity method to get the breadcrumb and called that method form the Rendering Variant Template item. Unfortunately as Elena said in the previous comment it's not possible for now. Commented May 9, 2019 at 12:21
  • 1
    Thanks for responding, I have logged something with support as it would be so handy if this just worked!
    – Jen
    Commented May 10, 2019 at 0:39
  • 1
    @Jen any luck with finding a fix or reply from sitecore? If so could you please share or answer to this question. Thanks Commented Dec 18, 2019 at 11:16

1 Answer 1

1

This was acknowledged as a bug - reference 338019

I ended up create an extension to resolve a $breadcrumb token along the lines of:

public class ResolveBreadcrumb : ResolveVariantTokensProcessor
{
        public override string Token => "$breadcrumb";
        private const string BREADCRUMB_SEPARATOR = "<span class=\"breadcrumb-chevron\">></span>";

        public override void ResolveToken(ResolveVariantTokensArgs args)
        {
            if (args.ResultControl != null)
            {
                args.ResultControl.Controls.Add(new LiteralControl
                {
                    Text = GetBreadcrumbPath(args.ContextItem, Sitecore.Context.Site)
                });
            }
            else
            {
                args.Result = GetBreadcrumbPath(args.ContextItem, Sitecore.Context.Site);
            }
        }

        private string GetBreadcrumbPath(Item contextItem, SiteContext site)
        {
            StringBuilder breadcrumbString = new StringBuilder();
            var ancestors = GetBreadcrumbs(contextItem, site);

            return string.Join(BREADCRUMB_SEPARATOR, ancestors);
        }

        private ICollection<string> GetBreadcrumbs(Item current, SiteContext site)
        {
            List<string> breadcrumbs = new List<string>();

            while (current != null)
            {
                var breadcrumbValue = current.DisplayName;
                if (current.Fields["NavigationTitle"] != null && !string.IsNullOrEmpty(current.Fields["NavigationTitle"].Value))
                {
                    breadcrumbValue = current.Fields["NavigationTitle"].Value;
                }

                // could add additional logic to opt in/out of 
                // the breadcrumb based on a template/field
                breadcrumbs.Add(breadcrumbValue);

                if (current.TemplateID.ToString().ToUpper().Equals(Constants.HomePageTemplateId))
                    break;

                current = current.Parent;
            }

            breadcrumbs.Reverse();

            return breadcrumbs;
        }


    }

Which is used in a rendering variant for the search results: enter image description here

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.