Orchard Hungary is an archive

This site is now an archive. We'll keep it so the content is accessible, but we won't update it anymore. However, we frequently publish Orchard-related news on our other site Orchard Dojo, so be sure to check that out instead. And if you're interested in news about our Orchard development company, Lombiq, check out our website.

Orchard Gems: module name class on the html tag

Tags: styling, CSS, Orchard gems, Orchard

Proper styling often takes up a big piece of development time, when we're hunting pixels for hours, so that even users looking at the website through a refrigerator's built-in console running some exotic fork of Windows CE can experience the same as an IE 6 user. Just kidding, it's worse than that. Anyway, there is a nice feature in Orchard that could help targeting elements of the layout: automatic classes on the html tag.

If you use a theme that doesn't override the core Document.cshtml template you'll notice that when you visit a page corresponding to a module (i.e. that goes through a custom controller) the html tag's class attribute will contain the name of the module. For example, the "Change Password" page has "orchard-users" appended. Nice indeed.

Actually the piece of code giving us this functionality is the Html.ClassForPage() helper, what's in the Orchard.Mvc.Html.LayoutExtensions class. On line 68 there is a comment from "heskew" (who I believe is Nathan Heskew):

//todo: (heskew) need ContentItem.ContentType

Meaning that also a class for the type of the current content item could be added. And we couldn't agree with Heskew more :-).

No Comments