Skip to content

Instantly share code, notes, and snippets.

@nul800sebastiaan
Created September 26, 2011 07:12
Show Gist options
  • Save nul800sebastiaan/1241761 to your computer and use it in GitHub Desktop.
Save nul800sebastiaan/1241761 to your computer and use it in GitHub Desktop.
Modify the body tag with Razor in Umbraco
<umbraco:Macro runat="server" Language="cshtml">
<body class="@Model.NodeTypeAlias.ToLower().Replace(" ", "-")">
</umbraco:Macro>
@nul800sebastiaan
Copy link
Author

In your template (masterpage) just surround the body tag with a cshtml (Razor) macro.
Here, the class gets set to the alias of the document type (NodeTypeAlias), spaces replaced by dashes. This way, our frontend developer can easily style pages with a specific document types differently.

Unlike XSLT, there's no need to produce valid XML from a Razor file, so you don't need to close the body tag here.
(but remember, with great power comes great responsibility...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment