Using content fields in a view

Topics: Customizing Orchard
Nov 16, 2011 at 11:14 AM
Edited Nov 16, 2011 at 11:16 AM

Hi there,

I added a content field called 'PageBodyId' to my Page content type. I've copied the core document.cshtml into the /Views folder of my theme and I want to make a modification that will generate the following markup:


<body id="myPageId">


If would have expected the following would do the trick:

<body id="@if (Model.PageBodyId != null)

Maybe this isn't possible in document.cshtml? However I don't know how to get at the value of the content field from a view at all.

Liking the product so far, thanks in advance for any assistance.

Nov 16, 2011 at 12:23 PM

The way to do this is:

  • In Content.cshtml, where you have access to the content item, store that value somewhere you can find it (e.g. Layout.PageBodyId)
  • In Document.cshtml, you should then be able to retrieve it from @Layout.PageBodyId

See this similar thread about passing the page title into Branding: