Manage Zones in theme's layout.cshtml

Topics: Customizing Orchard, Writing modules
Apr 4, 2013 at 2:34 PM
Hi,
In my site I am having some pages with 2 column and some with 3 columns. So I have developed 2 layers with name as 2-Col Pages and 3-Col pages. Now in 3-Col pages layer I am adding some HTML widgets in Asidesecond zone(I am using Default theme) which I do not want in 2-Col Page layers. So I have written a code in my layout.cshtml page as below

@if (Model.AsideSecond != null)
{
   <div class="rightCol">
          @Zone(Model.AsideSecond)
   </div>
}

Now my problem is that, in Col-2 pages above condition is getting true and div with class “rightCol” is displaying on front end. What condition should I apply here to now showing div with class “rightCol” in Col-2 pages.
Developer
Apr 4, 2013 at 7:00 PM
If you have widgets in the AsideSecond zone for the 2-Col layer, this zone will never be null. You could write a method that scans the contents of the AsideSecond zone, but that's both brittle and ugly, so I won't mention that. :)

You probably should try another approach, for example create a couple of Layout files, implement IShapeTableProvider, or write conditional logic in the Layout file, etc. It depends on what determines which layout to render.
Apr 5, 2013 at 5:54 AM
Apr 5, 2013 at 3:02 PM
Hi sfmskywalker,
With refence to your post above, I just want to know that what code should I write in Layout file for coditional logic. I have already apply logic for checking null as
@if (Model.AsideSecond != null) but this code is not working.

Please sugget correct code.
Developer
Apr 5, 2013 at 6:02 PM
Tricky, because I can't tell you what the correct code should be, as I have no idea why and what shapes there are inside of the zone.
If you think the zone should not contain any shapes and therefore be null, you need to investigate what shapes are being added and why, so you can correct that.
If the zone does not contain any shape, you should be able to check against null.