Model.ContentItem - within Layout.cshtml

Topics: Writing themes
Sep 3, 2012 at 10:00 PM

Why would this always be null from the Layout.cshtml?

I have added a new text field to the Page Content Type and would like to use the value of that text field to determine a class name; but everytime I reference Model.ContentItem - it's always null.

What's the best way to access this field (assume the name of the field is ClassName )

Any help is appreciated.

thanks

Sep 5, 2012 at 6:03 PM

Discovered that I need to add a line of code to the Content-Page.cshtml (same one that sets the page Title) and set the dynamic variable "Layout" to support ContentItem.

(e.g. Layout.ContentItem = Model.ContentItem)

Now I have access to ContentItem from within the Layout.cshtml.

When not using the Content-Page.cshtml alternate; the ContentItem is still null; so I'm not sure how everyone else's is not null unless they are setting it elsewhere.

Hope this helps someone.

thanks

Coordinator
Sep 12, 2012 at 10:53 PM

Because there is no content associated with Layout unless you do what you did in your second post. The content item gets rendered in the Content zone that is in layout.

Everyone else's *is* null.

Sep 13, 2012 at 12:43 AM

lol - thanks!