Hi all,
is it possible to fill the code editor with an existing .ps1 script?
My code does not work:
New-UDCodeEditor -Height ‘500’ -Language ‘powershell’ -Id ‘editor’
if (Test-Path D:\UniversalDashboard\SCRIPT\script.ps1) {
$script = Get-Content D:\UniversalDashboard\SCRIPT\script.ps1
Set-UDElement -Id ‘editor’ -Attributes @{
code = $script
}
}
Daniel
2
i think get-content needs to have the option -raw at the end…
without -raw you will get an array auf strings… but the editor aks for string… i belive
fkappen
3
tried it - doesn’t work …
adam
4
This works for me.
New-UDCodeEditor -Height '500' -Language 'powershell' -Id 'editor'
New-UDButton -OnClick {
Set-UDElement -Id 'editor' -Attributes @{
code = 'heelo'
}
}
I think your example doesn’t work because the editor isn’t yet loaded when you call Set-UDElement. I would change your example to:
$Script = ""
if (Test-Path D:\UniversalDashboard\SCRIPT\script.ps1) {
$script = Get-Content D:\UniversalDashboard\SCRIPT\script.ps1
}
New-UDCodeEditor -Height ‘500’ -Language ‘powershell’ -Id ‘editor’ -Code $Script
Works. Magnificent work =)