8

I have problems using conditional renderings with MVC (on Sitecore 8.0 rev. 150121)

I've created a condition and assigned it to the controller rendering but this condition never gets called.

From what I see the conditions attached to the renderings are triggered in the insertRenderings pipeline which doesn't seem to be executed when we have an MVC layout.

Am I missing something or the conditional renderings are supported only with Web Forms? If so I am wondering is there a graceful way to make it work with MVC

  • 1
    where are you setting the condition? on the presentation of the item or a global condition? – Richard Seal Oct 6 '16 at 13:07
  • In MVC renderings are customized via mvc.customizeRendering pipeline. If you are talking about code you would need to provide additional implementation for MVC. – Alan Płócieniak Oct 6 '16 at 13:15
  • @RichardSeal I am setting the condition on the presentation details (under Personalization section of rendering options) – Alexander Mogilka Oct 6 '16 at 13:50
11

Conditional renderings work fine with MVC. For version 8, you must have Analytics.Enabled set to true so you can get to the personalization section of the presentation.

"Global" conditional renderings do not work with MVC, so you need to stick to personalization of the rendering on the items presentation rather than a global rendering rule.

Here is how you set a Personalization rule. Edit the items presentation and then edit the Device you need. Most likely the Default one.

Select the rendering you want to personalize and click the Personalize button. If that button is not visible, Analytics is disabled:

Edit the Presentation

Then you can add a new condition:

Add a condition

You can click the edit button to edit the rule for your condition. Add as many variants as you need, you can hide component, change the Datasource etc...

  • Could you please point out which pipeline/processor is responsible for executing rendering conditions on MVC? – Alexander Mogilka Oct 6 '16 at 13:58
6

The conditions you set under Personalization section are Global Conditional Rendering Rules and are not supported in Sitecore MVC.

MVC does not support global conditional rendering rules (the rules that apply to all renderings).

This means that when you use MVC, you cannot set up a system of global conditions that determine which content is displayed to website visitors who meet these conditions every time the rendering is called.

It should be possible to make them run by adding in some appropriate processors overrides in the correct MVC pipelines, but this is likely to have a solution wide performance impact since the rules would run for every single rendering. This is most likely the reason it was removed in the first place.

The global rules do however still work with WebForms only solutions.

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.