Unable to get Dynamic Pages working


#1

Hello,

I am not able to get Dynamic pages working in UDash. Here is the script:

Import-Module UniversalDashboard

Get-UDDashboard | Stop-UDDashboard

if (Test-Path variable:global:psISE)
{
$ScriptDir = Read-Host “ISE detected. Please enter script directory.”
}
else {
$ScriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

}
$Init = New-UDEndpointInitialization -Variable “$Scriptdir”

$Dynamic = New-UDPage -Url “/dynamic/:Name” -Endpoint {

param($Name)
    
New-UDCard -Title "Welcome to a DynamicPage, $Name!" -Text "This Dynamic Page seems to be working"

}

$TestDash_1 = New-UDDashboard -Title “Dynamic Pages Test” -Content {

New-UDInput -Title "What is your Name?" -Endpoint {

    param($Name)
    
    New-UDInputAction -RedirectUrl "/dynamic/name"

}

} -EndpointInitialization $Init

Start-UDDashboard -Port 1001 -Dashboard $TestDash_1 -AutoReload

As you can see, I basically copied an example I found online. When I run the script, I do not get any error messages. When I browse to the dashboard (tried with both Chrome and IE), I enter some text in the input field and click the submit button. The New-UDInput works because it posts the text to a text file in the script directory After that, I am still looking at the home page, so the redirection has not taken place and no new page has been built. Not sure what I am doing wrong, but it feels like the problem is with the Url and hoe I am creating/referencing it. The Udash version is 2.2.1

Thanks

L


#2

Your $Dynamic variable is never added to New-UDDashboard.
Here is the basic working code:


Get-UDDashboard | Stop-UDDashboard

$pages = @()
$pages += New-UDPage -Name 'home' -Content {
    New-UDInput -Title "What is your Name?" -Endpoint {
        param($Name)
        New-UDInputAction -RedirectUrl "/dynamic/$Name"
    }
}

$pages += New-UDPage -Url "/dynamic/:Name" -Endpoint {
    param($Name)
    New-UDCard -Title "Welcome to a DynamicPage, $Name!" -Text "This Dynamic Page seems to be working"
}

$TestDash_1 = New-UDDashboard -Title "Dynamic Pages Test" -Pages $pages

Start-UDDashboard -Port 1001 -Dashboard $TestDash_1

#3

Morning and thank you for the quick reply. I like the idea of building the $Pages hashtable up front and adding to it as needed. Looks like when you start the Dashboard you have to include -Pages $Pages to the command. The other thing I noticed is that when you are defining a Dynamic page, the -Name param is not allowed(or at least it didn’t work when I used it …). That, I believe is the main reason this was not working.

Thanks again!!

Larry