Model.Content != null is always true in layout.cshml

Topics: Customizing Orchard, Troubleshooting, Writing modules, Writing themes
Mar 7, 2012 at 3:14 PM
Edited Mar 7, 2012 at 3:19 PM

I needed my #layout-main to have two background images, one on the top and one on the bottom of the div. The easy fix is to use the CSS file to comma delimit multiple background images, however this doesn't work in ie 7.So what I did is add an additional div to the #layout-main div called #layout-main-bottom as a place to hook an background image onto.


<div id="layout-main-container">
<div id="layout-main" class="group">
    <div id="layout-content" class="group">
        <div id="content" class="group">
            <div class="zone zone-content">
		<article class="content-item page">
    			<header>
        
        			<div class="metadata">
            				<div class="published">Feb 28 2012 12:38 PM</div>
        			</div>
   			</header>
		</article>
		</div>
        </div>
    </div>
<div id="layout-main-bottom"></div>
</div>
</div>

This works fine for every page except that on the home page I don't have any content in the following zones: Header, Features, Tripel, Footer.I don't have any content in the Content Zone however as you can see above it is still outputting the content zone's meta data for some reason. I need this to be empty so I can do something like this in the Layout.cshtml


@if (Model.AsideFirst != null || Model.Messages != null || Model.BeforeContent != null || Model.Content != null || Model.AsideSecond != null) {
<div id="layout-main-container">
<div id="layout-main" class="group">
    @if (Model.AsideFirst != null) {
    <aside id="aside-first" class="aside-first group">
        @Zone(Model.AsideFirst)
    </aside>
    }
    <div id="layout-content" class="group">
        @if (Model.Messages != null) {
        <div id="messages">
            @Zone(Model.Messages)
        </div>
        }
        @if (Model.BeforeContent != null) {
        <div id="before-content">
            @Zone(Model.BeforeContent)
        </div>
        }
        @* the model content for the page is in the Content zone @ the default position (nothing, zero, zilch) *@
        @if (Model.Content != null) {
        <div id="content" class="group">
            @Zone(Model.Content)
        </div>
        }
        @if (Model.AfterContent != null) {
        <div id="after-content">
            @Zone(Model.AfterContent)
        </div>
        }
    </div>
    @if (Model.AsideSecond != null) {
    <aside id="aside-second" class="aside-second">
        @Zone(Model.AsideSecond)
    </aside>
    }
	<div id="layout-main-bottom"></div>
</div>
</div>
}

However since Model.Content != null (always displays the content meta data even if the content zone is empty) is always true, what's the best approach to this issue.

Basically the homepage is showing my background images for my #layout-main even though theres no content there. It's messing up the page!

Developer
Mar 7, 2012 at 5:35 PM

You can prevent the meta data from being rendered using Placement.info.

Mar 7, 2012 at 5:46 PM
Edited Mar 7, 2012 at 5:46 PM

This is what my placement.info in my themes folder looks like now, yes those are commented out atm.

<Placement>
  <!-- Customize where the shapes are rendered -->

  <Match Path="~/">
	<Place Parts_RoutableTitle="" />
  </Match>
  
  <!-- 
  <Place Parts_Blogs_BlogArchives="Content:before"/>
  <Place Parts_Blogs_RecentBlogPosts="Content:after"/>
  <Match ContentType="Blog">
    <Match DisplayType="Summary">
      <Place Parts_Blogs_Blog_Description="Content:before"
             Parts_Blogs_Blog_BlogPostCount="Meta:3"/>
    </Match>
  </Match>
  <Match Path="/About">
    <Place Parts_Common_Metadata="-"/>
  </Match>
-->
</Placement>

Mar 7, 2012 at 6:00 PM

Ok all I had to add was this.

  <Match ContentType="Page">
	<Place Parts_Common_Metadata="-"/>
  </Match>

Mar 7, 2012 at 7:36 PM
Edited Mar 7, 2012 at 7:40 PM

So I got to the point to where it's no longer displaying metadata, however it is still rendering html elements like empty <header> tags. Not sure why its passing if (@Model.Content != null) considering there is no actual content there anymore. 

<div id="content" class="group">
	<div class="zone zone-content">
		<article class="content-item page">
    			<header></header>
    		</article>
	</div>
</div>
Developer
Mar 7, 2012 at 9:22 PM

If you use the Shape Tracer, can you see any shapes in the content item?