2 column layout

Topics: General, Writing themes
Mar 7, 2011 at 7:11 AM
Edited Mar 7, 2011 at 7:12 AM

I would like to create a page with 2 columns on it.

I created a new theme based on TheThemeMachine

I added a HtmlField Field called RightColumn

I then copied the Layout.cshtml file from TheThemeMachine to my NewTheme.

How do I adjust the Layout.cshtml to only draw a right column if one exists?

Coordinator
Mar 9, 2011 at 12:50 AM

I don't understand the bit about an HtmlField Field.

The Layout file in theme machine already has code to only show each zone if it has contents.

Mar 9, 2011 at 5:32 AM
Edited Mar 9, 2011 at 5:32 AM

Oh yep, my fault. That is not clear. Here is my second try.

 

I would like to create a page with 2 columns on it.

I created a new theme based on TheThemeMachine

I added and enabled the HtmlField Module.

I then added a HtmlField called RightColumn to the Page Content Type.

I then copied the Layout.cshtml file from TheThemeMachine to my NewTheme.

if I would like to render another div with the id="contentright" directly after the div with id="content"

How do I adjust the Layout.cshtml to only draw a right column if one exists? I am stuck on the syntax of checking if RightColumn Field is empty or not and redering the value of that field as well.

ie (this doesn't work)

@if (Model.RightColumn != null) {

<div id="contentRight" class="group">

@Zone(Model.RightColumn)

</div>

}


Coordinator
Mar 9, 2011 at 5:42 AM

I see. You'll have to do things a little differently. I would write a handler that handles OnDisplaying, I'd check if the current content type is page, and if it is I'd access the layout from the work context, then that rightColumn zone from there, then create a shape and add that to the zone. The shape should have the field value as one of the properties. You can then build a template for the shape that displays the value from the shape.

What you tried can't work because at the layout level you can't know that a content item is going to be displayed in the content zone, let alone what kind of content item. You need to do things from a place where that information is available.

Mar 9, 2011 at 6:41 AM
Will the “Orchard dynamic layout platform” discussed in http://orchard.codeplex.com/discussions/248945#post577497 allow me to do this without writing c# code?
If not, Is there any items in feature list or bug list that you are aware of that I can vote for to get it higher in the list of things to do if this is a desirable feature?