Adding shape to zone only if zone will be rendered

Topics: Customizing Orchard, Writing modules
Feb 21 at 11:53 AM
I'm adding a "These items might also interest you" block to some of my pages and came up with filling a custom zone for it with the shape(s) needed from inside an ActionFilter using something like this:
_services.WorkContext.Layout.Zones.PremiumBlock.Add(premiumBlockShape);
Now, I have the problem that I'm doing the work to render that premiumBlockShape on all requests (actions) that return a ViewResult although on some pages I won't ever render that shape.

The only way I see right now to solve this problem is doing all the work from inside the shape template which itself will only be processed if the containing zone is actually rendered. But it feels awkward to do all the heavy lifting from inside a View!

How would you go about this? Any other ideas?
Developer
Feb 22 at 11:09 AM
You could give the shape a factory delegate or even a service object that will be only executed (and thus do the heavy lifting) when the template is actually rendered.
Mar 3 at 9:02 PM
Edited Mar 3 at 9:03 PM
Thanks, Piedone, for your answer. That's what I did now, and even though all the processing is done only once the View is being rendered, this solution is clean and works.