2
votes

I am attempting to utilize conditional rendering on Mvc renderings in my Sitecore items. Regardless of the condition I select, none of the rules actually fire, including the default condition. In other words, the component always renders, whether the "Hide Component" checkbox is checked or not. My troubleshooting thus far has not revealed the root cause. Has anyone experienced this issue before?

Additional information:

  • The sitecore logs do not show any errors during the authoring process or when accessing the content item from my web browser.
  • I am using the out-of-the-box CustomizeRendering.Personalize processor.
  • I am working with Sitecore 6.6.0-Update 4.
  • Analytics is enabled.
  • MVC is enabled.
  • I have performed IIS resets between making changes to the conditional rendering settings to ensure that the page was not being cached.
  • When trying custom conditions, I have set breakpoints in Visual Studio on the "process" method of these custom conditions. The breakpoints never hit.
  • To test whether my conditions were bad, I set up a template that inherits ItemRules, and explicitly invoked RuleList<>.Run(context) in the controller. My custom conditions hit their breakpoints during this test.
1
Do the components have caching enabled by any chance? Are the rules set on individual components or are they global rules? - jammykam
Are you using Preview mode? I remember something not working on preview mode, but that might be goals... Just in case, you could append your URL with sc_mode=normal - Trayek
@Jake when you're logged in to Sitecore and use the same browser to browse the site you'll be logged in there too - even without having the sc_mode=preview, it could still be doing a preview. sc_mode=normal would fix that (and set Sitecore.Context.PageMode.IsNormal to true) - Trayek
I agree with Trayek on this, if you are logged into Sitecore and are viewing the site in the same browser, sometimes strange things will happen. I always test my presentation in a different browser/session than the one used to log into the desktop. - Richard Seal
Are you using setting up the conditional rendering via the "Personalize component" in the Page Editor? Try using the "where true" rule (very last one in list of available rules). And remember that the conditions are evaluated from the top - so any rule preceding your hide component condition could prevent it kicking in. - herskinduk

1 Answers

1
votes

As mentioned by Trayek above, preview mode was to blame.

Diving into the Sitecore assemblies, it turns out that CustomizeRendering.Personalize.Process() requires "Sitecore.Context.PageMode.IsNormal" to evaluate to true in order to call the method that evaluates conditional renderings, and my value is set to false.

"Sitecore.Context.PageMode.IsPreview" is true.

This explains on an abstract level why conditional rendering is not firing. I am unsure why my site is defaulting to Preview mode, even when I am not logged in, but that is the immediate cause of conditional renderings not being evaluated.