SnV
March 16, 2021, 4:23pm
1
Hey,
Like with the cascading style sheet is there a way to load a theme file from a published folder?
When I do the following it gives me an error:
New-UDDashboard -Title ‘Home’ -theme @("/themes/Theme.ps1") -Content {
}
Theme.ps1 tested in 2 formats
@{}
$theme = @{}
Thanks
SnV
March 16, 2021, 4:34pm
2
Also tried loading like (. “/themes/theme.ps1”)
SnV
March 16, 2021, 5:55pm
3
This is the error I am getting:
Cannot process argument transformation on parameter ‘Theme’. Cannot convert the “System.Object[]” value of type “System.Object[]” to type “System.Collections.Hashtable”.
Snippit form the theme file:
@{
light = @{
palette = @{
Common = @{
black = ‘#000 ’
white = ‘#fff ’
}
primary = @{
main = ‘#939b38 ’
light = ‘#7986cb ’
dark = ‘#303f9f ’
contrastText = ‘#fff ’
}
Have you tried
Get-Content '/themes/Theme.ps1' -Raw
SnV:
@(“/themes/Theme.ps1”)
Also, this^ is an array
“/themes/theme.ps1”
^ this is a string
$(“/themes/theme.ps1”)
^ this is also a string
$(Get-Content -Path “/themes/theme.ps1” -Raw)
^ this will load the contents of the file into the temporary variable $()
If you just want to use the filename, you do not need to surround it in anything.
That is why you’re receiving this error:
[System.Object[]]
Is an array of objects
adam
March 17, 2021, 9:16pm
6
The -Theme parameter is expecting a hashtable so you will need to convert the string content from the theme into a hashtable.
Using a published folder isn’t really necessary here. You could instead use Import-PowerShellDataFile to load the file from disk.
$Theme = Import-PowerShellDataFile -Path "$PSScriptRoot\Themes\Theme.ps1"
If you want to load it via the published folder, you will have to load it with Invoke-WebRequest.
$Response = Invoke-WebRequest "http://localhost:5000/themes/theme.ps1"
$Theme = Invoke-Expression $Response.Content
SnV
March 18, 2021, 2:17am
7
Thank you for this very helpful!!
SnV
March 18, 2021, 3:18am
8
Got a strange issue with the above.
Loading the file as such:
$Theme = Import-PowerShellDataFile -Path “$PSScriptRoot\Themes\Theme.ps1”
Works no problem.
Loading the Theme
$Response = Invoke-WebRequest “http://localhost:5000/themes/theme.ps1 ”
$Theme = Invoke-Expression $Response.Content
Gives me a diffrent color for the main even though its set correctl
I deleted and readded the published folder incase it was cached and restarted the service. Nothing changed that.
Browsing to the file shows it correct too.
adam
March 18, 2021, 1:59pm
9
What happens when you output the $Theme returned by Invoke-Expression?
Maybe something like:
Show-UDToast -Duration 10000 -Message ($Theme | ConvertTo-Json)
SnV
March 18, 2021, 2:07pm
10
I did that it looks correct and has all the same values.
thanks
adam
March 19, 2021, 1:03pm
11
Strange. I would suggest going the local file route then over the published folder since there is something that isn’t quite right there.
1 Like