This project is read-only.

Using content fields in a view

Topics: Customizing Orchard
Nov 16, 2011 at 12:14 PM
Edited Nov 16, 2011 at 12:16 PM

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 1: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: