Pages as separate Files

I may push the limit on stupid questions, so here goes…

I have one big file with navigation, pages and so on and it works, but it’s getting uglier by the minute. What’s the preferred way to split pages out into separate files? I may have overlooked it in the documentation.

I like to put each page in it’s own file.

Then loop through and load em up.

Then I usually do some custom navigation but not necessary if you are using named pages.

1 Like

That makes perfect sense. Thank you! I was curious about the loading process. Are all pages processed in sequence as the first page is loaded?

As you execute the PowerShell script, it will load those pages in the order you put them in there. Once your dashboard is running, all the pages are in memory so you shouldn’t have to worry about the order that they were added to that array. If you want a special order for the navigation menu, I’d suggest using the custom navigation cmdlets.

The only one that matters is which is the first one as it’s the home page. You can manually set the homepage using the -DefaultHomePage switch parameter.

1 Like

Awesome!! I was just about to log in here to check if anyone had done this. So much easier to split things up in pages :wink:

1 Like

I may be doing it wrong, but it seems that the $Cache object is easiest for sharing common configuration data across pages. I’m still figuring out variable scopes and how they work inside and outside of the cmdlets. For example, if I reference a $Cache variable at the top of a page script, but above New-UDPage, it sometimes doesn’t see it nested within a lower-level function like New-UDCard. But if I reference it inside the -Endpoint {} section of the nested object it works fine.

It sounds like you’re misinterpenting how UD executes the code.
When you’re referencing a $cache value, it will show you the value of said $cache value at the time of execution. “-content” scriptblocks are generated (unless they are children of an endpoint) during the initialization of UD, while “-endpoint” scriptblock are generated at every request.

If I misunderstood you, or if you need any further guidance: feel free to share some code examples where you can replicate the issue :slight_smile: