Question

I would like to do the add skin support for an mvc application, allowing to add multiple skins and let the user select the prefered one.

the skin directory will be received in cookie from the database

In order to make this happen i would like to create a parametrized bundle that takes as input the directory specified for the skin and dynamically creates the bundle for the specified path

bundles.Add(new StyleBundle("~/Content/css")
            .Include(
            "~/Content/{skinDirectory}/reset.css",
            "~/Content/{skinDirectory}/site.css",
            "~/Content/{skinDirectory}/grids.css")
            );

where {0} is the directory name that i send from the bundle, and i call it in my _Layout page like this:

@Styles.Render("~/Content/css", skinDirectory)

is this possible?

Was it helpful?

Solution

This might be a bit late but could probably help someone else. Yes, this is possible.

public static class DynamicBundles
{
    public static IHtmlString RenderSkin(string skinDirectory)
    {            
        BundleTable.Bundles.Add(new StyleBundle("~/Content/css/" + skinDirectory).Include(
            "~/Content/" + skinDirectory + "/reset.css", 
            "~/Content/" + skinDirectory + "/site.css", 
            "~/Content/" + skinDirectory + "/grids.css"));

        return Styles.Render("~/Content/css/" + skinDirectory);
    }
}

and then in your _Layout page use

@DynamicBundles.RenderSkin(skinDirectory)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top