KB0043 - Configure CSS based on user or page

KB0043 - Configure CSS based on user or page

Problem

As of version 4.0.x, PowerShell Universal only supports specifying CSS on the New-UDApp cmdlet via the -Stylesheet parameter. This parameter is global for the entire app and does not change based on user or page. 

Solution

Include with PowerShell Universal v4, you can use the New-UDHelmet cmdlet to add arbitrary header elements to the HTML page. This means that you can add logic within your page to determine which CSS file to load. 

Below is an example of using the cmdlet to add a stylesheet link to a CSS file. 
  1. New-UDHelmet -Tag link -Attributes @{
  2.     rel = 'stylesheet'
  3.     href = ' https://.../stylesheet.css '
  4. }
Here is an example of only applying a stylesheet if the user is an administrator. 
  1. Protect-UDSection -Role 'Administrator' -Content {
  2.     New-UDHelmet -Tag link -Attributes @{
  3.          rel = 'stylesheet'
  4.          href = ' https://.../stylesheet.css '
  5.     }
  6. }

    • Related Articles

    • KB - 1008 Tax/VAT Exempt at checkout

      Scope In this article you will learn how to make a tax-free purchase at checkout. Problem How do you remove the Tax/VAT on an order? Impact Orders will then need to be refunded for tax if processed without the tax deducted. Resolution Follow the ...
    • KB0072 - UDDataGrid expands beyond the size of the screen

      Scope This article applies to users creating apps within PowerShell Universal and using UDDataGrid. Problem The data grid does not have any defined size. It will expand to the size of its container. This could be elements such as the page itself, a ...
    • KB0055 - Blank Admin Console or No Updates After Upgrade

      Affected Versions - PowerShell Universal 4.2.x Problem When navigating to subpages (such as /admin/automation/scripts) in the admin console, the page will display a blank page. Navigating directly to the /admin URL will load the page. Additionally, ...
    • KB0044 - High memory usage in a long running, complex App

      Problem Memory usage can grow continuously in a complex app that is either long running and\or very busy. Root Cause Apps maintain user state as the users interact with the app. This state includes variables that are set and event handlers that are ...
    • KB0017 - Windows Auth Checklist

      Purpose The purpose of this article is to list the prerequisite conditions for ensuring that Windows Authentication in PowerShell Universal will function as expected (i.e. seamless logon without authentication pop-ups) Scope The scope of this article ...