Copied to clipboard

Flag this post as spam?

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


  • Sam 79 posts 426 karma points
    Oct 21, 2016 @ 20:55
    Sam
    0

    Condition based on hostname and cultures

    Hello all,

    I have two sites running in one back office, and I want them to run the same template too. the only differences will be style changes.

    I would like to know if there is a way to use the hostname deffined in cultures and hostnames to render style sheets...

    <link rel="stylesheet" type="text/css" href="/css/Style.css">
    
    @if (hostname) == test.example.com){
        <link rel="stylesheet" type="text/css" href="/css/TestStyle.css">
    }
    

    Thanks in advance.

  • Jeremy Newman 18 posts 190 karma points
    Oct 21, 2016 @ 22:13
    Jeremy Newman
    100

    You can use the Site Name... which is the top level node name of the site and then...

    @using ClientDependency.Core.Mvc
    
    @if(Model.Content.Site().Name == "Site1")
    {
         Html.RequiresCss("style1.css");
    }
    else if(Model.Content.Site().Name == "Site2")
    {
        Html.RequiresCss("style2.css");
    }
    

    From there you can refactor or wrap it in something more elegant...

    You really wouldn't want to tie it to the external dns because if you changed it you would have to change code.

  • Sam 79 posts 426 karma points
    Oct 25, 2016 @ 15:25
    Sam
    0

    Thanks Jeremy, That was what i was looking for. I ended up using the node Id instead of the name.

    @if(Model.Content.Site().Id == 1090)
    {
        Html.RequiresCss("style1.css");
    }
    ...
    
  • Jeremy Newman 18 posts 190 karma points
    Oct 25, 2016 @ 15:33
    Jeremy Newman
    0

    Glad to hear.

Please Sign in or register to post replies

Write your reply to:

Draft