You're quite right about why it's not working - MVC renderings don't execute the global conditional rendering rules.
This is not something I've had to do, but here's a suggestion. Someone might be able to suggest a better method, but here are a couple of suggestions:
Setting parameters during rendering
You could look at amending the mvc.renderPlaceholder
pipeline to achieve what you want. The processor Sitecore.Mvc.Pipelines.Response.RenderPlaceholder.PerformRendering
is what retrieves the renderings for a placeholder and calls the mvc.renderRendering
for each. It doesn't pass any placeholder information into this pipeline, so you would need to act here.
This is the method:
protected virtual void Render(string placeholderName, TextWriter writer, RenderPlaceholderArgs args)
{
foreach (Rendering rendering in this.GetRenderings(placeholderName, args))
PipelineService.Get().RunPipeline<RenderRenderingArgs>("mvc.renderRendering", new RenderRenderingArgs(rendering, writer));
}
You could extend this processor and override this method with one that executes rules for the rendering. It could then update the rendering
item that gets passed into the pipeline.
It's worth considering that Sitecore perhaps didn't implement the rules here due to performance issues, so rather than reintroduce global conditional rendering rules across all MVC renderings, you might want to make this a tailored processor that only acts differntlydifferently for particular renderings. This amended processor could potentially just inject the placeholder name into the rendering parameters, and then the rendering itself could decide how to act upon this.
Setting parameters upon saving
As an alternative method, though one that depends on the nature of your solution, would it be appropriate to perhaps tackle this problem at the source rather at rendering time?
For example, when the item is saved you could have an event that is triggered that looks through the placeholders + renderings and injects parameters into the renderings as required, which then get saved into the item. This way the rendering process doesn't need to be changed at all.