0

I have a website developed using ASP.Net MVC. Now I want to based on the request(based on the country) I want to change the web site theme.

Ex: for USA - theme 1 for Canada - theme 2

If the request is not matching to any theme I want to display default (my current theme).

How can I achieve this dynamically.

Do I need to rewrite my css again or Is there a better way to this?

Please share your ideas

Thanks in Advance :)

2
  • 1
    Why not just have a common css file that holds non-country specific styles. Then when you detect the country, lets say you get a country code of UK for united kingdom, you then import a specific gb.css to apply over the top of your base CSS. Commented Jun 28, 2011 at 5:53
  • Actually my site layout wont change. If I can change images theme can be change. So Can I create image folders (like theme1, theme2) then Can I load those images ?? But is it possible to change css dynamically. Ex: I have change image path written in css file Commented Jun 28, 2011 at 6:11

2 Answers 2

1

You should define a global css file for common styles. Assuming you have some kind of helper method for accessing the current country, you can conditionally load the country specific stylesheet, or load a stylesheet based on a rule e.g. stylesheet with the same name as the country (following code is untested):

<link rel="stylesheet" type="text/css" href="css/global.css">

// conditional

@if (SiteHelper.CurrentCountry == "USA") {
    <link rel="stylesheet" type="text/css" href="css/usa.css">
}

// or assume a css file exists with the country name

<link rel="stylesheet" type="text/css" href="css/@(SiteHelper.CurrentCountry).css">

I would generally recommend using a different layout page for each country/theme as it gives you much more control. Essentially you would move the above logic into _ViewStart.cshtml and set the Layout based on the current country.

Sign up to request clarification or add additional context in comments.

Comments

0

Not sure if this is the best approach but this is what I am doing. I have a folder structure similar to this:

   /Content
    layout.css
   /Content/Images
   /Content/Themes/ThemeUSA
                   layout.css
   /Content/Themes/ThemeUSA/Images

Then I use Helper Extensions to return the correct path for example for an image:

<img src="@Url.Image(Model.EnhImg)" alt="@Model.EnhImgAlt" />

where

public static string Image(this UrlHelper helper, string fileName)
{
    string sLocation = Content() + "images/" + fileName;
    return helper.Content(sLocation);
}

private static string Content()
{
    string sLocation = "~/content/";
    string sTheme = (string)HttpContext.Current.Session["Theme"];
    if (!String.IsNullOrEmpty(sTheme))
    {
        sLocation += "themes/" +sTheme + "/";
    }
    return sLocation;
}

Images in the theme folders have the same name as in the default folder. Same thing for stylesheets.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.