Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • BEWD 73 posts 245 karma points
    1 week ago
    BEWD
    0

    Different stylesheet per site in Multi Site Umbraco instance

    Hi

    I am currently building a website in Umbraco 8 that consists of a holding company site and then 4 other sites which are child sites within the same Umbraco instance. Basically it’s a bar / pub company and its 4 difference venus. Each site will have exactly the same layout etc but the styling, colours etc will be different per site.

    Because the layout is consistent regardless of what site you are on I don’t want to create different MasterPages but I can’t figure out how I can assign a different stylesheet depending on what site I am on?

    Basically the structure is as follows and for each pub site I would like to use a different stylesheet while only keeping one masterpage. Is this something that’s possible?

    Home

    --- About Us

    Pub Site A

    --- About Us

    Pub Site B

    --- About Us

    Pub Site C

    --- About Us

    Thanks

    Ben

  • Corné Hoskam 23 posts 291 karma points
    1 week ago
    Corné Hoskam
    0

    Hi BEWD,

    Absolutely, nothing that's stopping you from doing this! One of the ways to solve this, would be to dynamically set the Stylesheet you want to use in a master template from a (master-)controller, and depending on which domain is requested, choose the appropriate Stylesheet!

    Hope this helped!

    Corné

  • BEWD 73 posts 245 karma points
    1 week ago
    BEWD
    0

    Hi Corné

    Thanks for the reply, I have tried to assign stylesheets based on the parent page name etc but I cant get that to work. I have never done a multi site before so unsure how to do things based on domain name?

    Are you able to give an example as to how this could work?

    Thanks for you help

    Ben

  • Dennis 16 posts 170 karma points
    1 week ago
    Dennis
    101

    Hi BEWD,

    I might be able to give you an example! You need to perform this logic on every page, so what you can do, is create your own base controller and override the Index method.

    I would like to present a different approach to you though, which might be more suitable in cases where some sites do need a different stylesheet and some don't and the impact in your code is minimal.

    I suggest you make a child action controller to render your stylesheet like this:

    StylesheetController.cs

    public class StylesheetController : SurfaceController
    {
        [ChildActionOnly]
        public ActionResult Get()
        {
            var model = new StylesheetViewModel
            {
                Stylesheet = GetStylesheetByHostName(Request.Url.Host)
            }
            return PartialView("_stylesheet", model);
        }
    
        private static string GetStylesheetByHostName(string hostname)
        {
            // ... your logic to pick a stylesheet over here
        }
    }
    

    StylesheetViewModel.cs

    public class StylesheetViewModel
    {
        public string Stylesheet { get; set; }
    }
    

    Views/shared/_stylesheet.cshtml

    @inherits UmbracoViewPage<Stylesheet>
    <link href="@Model.Stylesheet" rel="stylesheet" />
    

    layout.cshtml

    <html>
    <head>
        @Html.Action<StylesheetController>(nameof(StylesheetController.Get))
    </head>
    </html>
    

    I hope this helps!

  • Marc Love (uSkinned.net) 381 posts 1086 karma points
    1 week ago
    Marc Love (uSkinned.net)
    0

    Hi Ben,

    The uSkinned Site Builder allows you to have a multi-site environment with different styles (designs) applied to each site in Umbraco. You can sign up for a free hosted trial at:

    https://trial.uskinned.net

    All designs you will see in this demo are hosted on the same Umbraco Instance. You can switch between each design demo in the top dropdown.

    https://portal.uskinned.net/demos/stroma/24014/

    This could save you a lot of work straight out-of-the-box. You are not restricted on functionality and are able to extend the base functionality as you see fit.

    Cheers,

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft