App Dashboard SubFolders

Product: PowerShell Universal
Version: 5.6.6

I’ve been trying to figure out how to use subfolders for page organization and still having them get parsed/show up as pages.

For example, I have a page “Function1 Page.ps1”

New-UDPage -Url '/Function1/Page1' -Name 'Function1 Page' -Title 'Test page' -Content {
"Test page"
}

If I have this in the root of the pages folder, it loads it, it shows up in the pages tab, and I can browse to it. However, if I move it to a sub directory (such as Function1) to match the url, the page is no longer loaded.

I have tried a few different ways to get this to work without success, such as

New-UDApp -Title 'PowerShell Universal' -Pages @(
    Get-UDPage -Name 'Function1 Page'
    Get-UDPage -Name 'Function1/Function1 Page'
    Get-UDPage -Name 'Function1\Function1 Page'
)

But nothing seems to work. Is there documentation on how this can be done or would anyone be able to provide guidance on doing this?

Thanks!

Hey! So the URL is entirely separate from the actual local file path.

I personally don’t use Get-UDPage, but I did have a look at the parameters and I don’t see anything that allows you to specify a path, only a name, so I think you might be restricted on that front.

I however don’t use Get-UDPage, instead I have some code in my main dashboard/app .ps1 which uses get-childitem recursively on a “$Rootpath/content” folder, and everything in there is organised into sub folders and it just loads the pages in from there (I also have a commented json string which is used to fill out the parameters of new-udpage in each file, so i can keep everything in one place). My urls/page names are all relative to the parent domain though.

This way, I can keep all my pages nicely organised either by team, or function or both, and regardless of where I put them, as long as they’re in rootpath\content, they’ll load into the app.

I then define my navigation menu manually, and keep that organized in separate sections.

$Pages = @()
$PageFiles = Get-ChildItem "$RootPath/content" -filter "*.ps1" -Recurse
Foreach ($PageFile in $PageFiles){
    $PageMeta = Get-Content $PageFile -first 1
    if($PageMeta -like "#META#`*"){
        $PageSplat = $PageMeta.Substring(6) | ConvertFrom-Json | ConvertTo-HashTable

        $Pages += New-UDPage @PageSplat -Content {
            . $PageFile.FullName
        }
    }
}

Example page:

#META#{'title':'Page title','Name':'pagename', 'Role': ['role1','role2']}

New-UDHTML -Markup "Hello World"
1 Like

Nice, I like this approach. That means you can also add pages without needed to update the main app ps1. I am going to look into this for own setup. Thanks!

Yeah exactly! and all the parameters are in the page files themselves too. I just copy and paste an existing page, update the params, and then recycle the app and i’m good to go!

Oh, I forgot to mention, ConvertTo-HashTable is a custom function because you can’t splat form a PSCustomObject.

This isnt the one i wrote but I use something similar to this: PowerShell Gallery | Functions/ConvertTo-Hashtable.ps1 1.0.0.0

1 Like