Copied to clipboard

Flag this post as spam?

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


  • Lasse 49 posts 161 karma points
    May 20, 2019 @ 08:55
    Lasse
    0

    umbraco user identity css component

    Hello Forum,

    I have a rather simple question, is it possible to make a css component in my main.css class or a similar solution, according to the user identity

    i am not really a fan of having a lot of stying inside of my views if i can avoid it

    Example of my .cshtml

    @if (User.Identity.Name.Equals("TV"))
    {
      <style>
           .dataTables_filter, .dataTables_info, .dataTables_length, 
           .dataTables_paginate {
            display: none;
        }
    
        .card-body {
            padding: 0 5px;
        }
    
        h2 {
            font-size: 15px;
        }
    
        th, td, tr {
            font-size: 10px;
        }
    
        .btn-circle {
            width: 10px;
            height: 10px;
            text-align: center;
            padding: 3px 0;
            font-size: 6px;
            line-height: 1;
            border-radius: 10px;
        }
    </style>
    }
    
  • Søren Gregersen 436 posts 1874 karma points MVP 2x c-trib
    May 20, 2019 @ 09:33
    Søren Gregersen
    0

    css files are "flat" files - they are (normally) not processed by the server.

    I would suggest you embed your custom styles as done in your example.

  • Sean Mooney 131 posts 158 karma points c-trib
    May 20, 2019 @ 12:21
    Sean Mooney
    0

    In the past I have often added classes to the html (or other element) to handle situations like that.

    <html class="[email protected]">

    And then prefix your styles with that in your main.css file

    .user_XXXX .dataTables_filter { ... }

  • Gilles 25 posts 107 karma points
    May 20, 2019 @ 12:47
    Gilles
    0

    This is how I handle these situations: Add all your classes to your CSS file. They are not processed by the server.

    In the view, add something like this:

    @{
        string class = "some css classes"
        if(User.Identity.Name.Equals("TV")){
            class+=" TV_user_specific_class";
        }
    }
    <div class="@class">My content</div>
    

    Your CSS file shoud look like this:

    .some{
    }
    .css{
    }
    .classes{
    }
    .TV_user_specific_class{
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft