This project is read-only.

Adding shape to zone only if zone will be rendered

Topics: Customizing Orchard, Writing modules
Feb 21, 2014 at 12:53 PM
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:
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?
Feb 22, 2014 at 12:09 PM
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, 2014 at 10:02 PM
Edited Mar 3, 2014 at 10: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.