This project is read-only.

Using Alternatives for Document.cshtml

Topics: Core, Customizing Orchard, General, Troubleshooting, Writing themes
Mar 26, 2012 at 9:10 PM

I am currently working on a website that requires the ability to overwrite the document.cshtml file so that I can apply a specific CSS-class based on the user's current location.

I have attempted to use URL alternatives such as:

  • Document.cshtml
  • Document-url-AreaA.cshtml
  • Document-url-AreaB.cshtml
  • Document.url-AreaC.cshtml

however it appears that all of them use the Document.cshtml as opposed to using one based on the URL. I could easily understand that this is the intended purpose, however I was wondering if it would be possible to implement the functionality above.

I have also attempted to add a Content Field to my pages in hopes of being able to pull out the Content Field and set my body element to that specific value, for instance:

Content Field Value : "SiteA"

would render:

<body class='SiteA'> (in the document.cshtml file)

However, when I added the field, named AreaType, I was unable to access it from within the document.cshtml file. I edited the Content.cshtml to include the following:

@if(Model.AreaType != null){
    Layout.AreaType = Model.AreaType

and then used the following within the Document.cshtml page:

@{ string area = Layout.AreaType }

<body class='@area'>

However, none of these have worked. I am using Orchard 1.3.10 if that makes any difference, and I am open to any and all suggestions. Thanks!

Mar 27, 2012 at 6:43 AM

This has been cross-posted on StackOverflow. I answered there.

Mar 27, 2012 at 2:59 PM

Thank you Bertrand. I cannot describe how fond I am of Orchard and the things you guys are doing.