Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:26:35+00:00 2026-06-11T04:26:35+00:00

Background: I want to avoid creating an Alternate Layout for my home-page and I’d

  • 0

Background: I want to avoid creating an Alternate Layout for my home-page and I’d like to keep the “The Theme Machine” zones and layout next to intact, and actually “theme” most of everything using pure CSS. So I need to selectively target CSS to specific “pages”, including, and most importantly, the homepage. The simplest way to do that would be to add a class to the layout-wrapper “div” that wraps the entire layout. I could add a class to the “body” element by overriding the Document.cshtml file, but I really think it is cleaner to just work inside the Layout.chstml file and capitalize on the Model.Classes to add the needed CSS classes to the “opening” tag.

I’ currently doing something like this:

string area = Model.DesignatedAreaField;
Model.Classes.Add(string.IsNullOrWhiteSpace(area) ? "home" : area);

Model.Id = "layout-wrapper";
var tag = Tag(Model, "div"); // using Tag so the layout div gets the classes, id and other attributes added to the Model

I know that the Area will not cut, because the homepage, and other pages are all in the same area, and Model.DesignatedAreaField actually returns an empty string for either the homepage or other pages. So, in the end, the code above will ALWAYS generate the following markup (I’m showing the 3 tripels on the homepage):

<div class="home tripel-123" id="layout-wrapper">

I would like to be able to add the “home” CSS class only when the homepage is being displayed. Some pseudo-code would be as follow:

string wrapperCss = IsHomepage ? 'home' : Model.GetUrlPathOrSomethingUniqueForThePath();
Model.Classes.Add(wrapperCss);

This will allow me to, for example, make the main content shrink and float to the right, and put the tripels on its left (that’s how the home page design should look like, but I don’t want to write an entire different layout for the home if I could do the same with simple, targeted CSS).

UPDATE: Wiring up Bertrand’s answer

Bertrand’s answer allowed me to add a class to the wrapping DIV depending on the URL. He didn’t mention it (since Orchard is second nature to him 🙂 but you’ll have to add an include into the Layout.cshtml file and change “my” code accordingly:

@using Orchard.Utility.Extensions;
{
/* omitted for brevity, everything in between is the same as in the Theme's Machine layout file */

string area = WorkContext.HttpContext.Request.Path.HtmlClassify();
area = string.IsNullOrWhiteSpace(area) ? "home" : area;
Model.Classes.Add("url-" + area);

It results in the following class being added to the enclosing div:

1) When the homepage gets shown:

<div class="url-orchard-local- tripel-123" id="layout-wrapper">

2) When a page named Products get shown:

<div class="url-orchard-local-products" id="layout-wrapper">

My URL reads like this on my dev machine, running inside Visual Studio’s webserver:

http://localhost:30320/OrchardLocal/ or 
http://localhost:30320/OrchardLocal/Products 

I’m not betting my life, but I strongly believe that the “OrchardLocal” part will change in production once it is published, let me say, to Azure servers… So I’ve preemptivelly change the code to this:

string area = WorkContext.HttpContext.Request.Path.HtmlClassify();
if (area.LastOrDefault() == '-') {
    area = "home";
}
Model.Classes.Add("url-" + area);

Which results in this class when the “homepage” gets shown:

<div class="url-home tripel-123" id="layout-wrapper">

(Actually I’ve made the code above a one-liner abusing some ternary mixed with lambda operators 🙂

I’m inferring that the only time the HtmlClassify will return a “class” ending with ‘-‘ is when it is the homepage… Or the “root” for the site… I may well be wrong! 🙂

(Anyway I’m loving Orchard more than anything I’ve used in the past couple of years other than nHibernate, but, hey, Orchard uses it too! Perfect!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:26:36+00:00Added an answer on June 11, 2026 at 4:26 am

    Something like this should do the trick:

    Model.Classes.Add("url-" + WorkContext.HttpContext.Request.Path.HtmlClassify())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I want to access the cache of Chrome and Firefox in my Cocoa
Background : I want to create a custom VB compiler, extending the original compiler,
Background We want to run an FTP server on a Red Hat Enterprise OS.
Background: I want to show the time and date uptill only 1 week. After
I am from PHP background and want to give path to STATICFILES_DIRS in settings.py
I have an AsyncTask and on the background I want to start Service that
I want to background image be overflow from its parent. The solution must be
I have a gradient background and I want, slowly, for it to change colors,
I have a background image and want to add a transparent fill color on
I am developing a small app in which I want a background service to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.