Copied to clipboard

Flag this post as spam?

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


  • ws-graham 10 posts 91 karma points
    Feb 02, 2024 @ 16:20
    ws-graham
    0

    Apply custom css to admin groups

    Firstly hi to the community, as this is my first post having recently joined the world of Umbraco.

    I have this issue where I want to hide some elements of the backend to some of the admin users.

    The scenario is - If an Umbraco user is not in the group "Administrators" I want to apply a simple bit of css (a bit like this)

    /* Hide the add content button */
    .umb-grid-add-more-content {
        display: none;
    }
    /* Hide the add row button */
    .umb-add-row {
        display: none;
    }
    

    The aim is to hide buttons like "Add content" and "Add row" for these users, to limit the functionality around content creation to standard admin users.

    Has anyone done anything like this before, or have any ideas on how to achieve this?

  • ws-graham 10 posts 91 karma points
    Feb 05, 2024 @ 09:02
    ws-graham
    0

    This is the sort of thing i was thinking I could use razor syntax in an Umbraco template and it can check groups and apply the relevant CSS styling?

    @{
        var currentUserGroups = umbraco.library.GetCurrentMemberGroups();
        var customCssFileName = "";
    
        // Check user's group membership
        if (currentUserGroups.Contains("Group1"))
        {
            customCssFileName = "custom-group1.css";
        }
        else if (currentUserGroups.Contains("Group2"))
        {
            customCssFileName = "custom-group2.css";
        }
        // Add more conditions for additional groups if needed
    
        // Load the custom CSS file
        if (!string.IsNullOrEmpty(customCssFileName))
        {
            <link rel="stylesheet" type="text/css" href="~/css/@customCssFileName" />
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft