In this tutorial, you will learn how to get a list of unpublished pages using Episerver CMS v6. I've recently taken over a project that was developed by a third party company. The site uses a number of hub/stack pages. Within a side nav, this client wanted to dynamically create a menu by reading all hub pages underneath the current page. The client also wanted to see what the sidebar nav looked like in preview mode. Content editors could not fully preview a stack page correctly if any of the subpages hadn't been published.
The fix was to update the template to allow editors to view the unpublished child pages in preview mode. The first part was finding out if the current request was being made via the editor or from the website, this was done by checking if the SystemPageBase
type had been populated. In edit
mode it will be false
and for a normal request it will be true
:
The next step was getting all child pages for a stack page, regardless of published status. This is possible using the code below:
When this code executes, if a page is unpublished, not all the properties in PageData
are correctly populated. From the Episerver forum, this looks like a known bug. To overcome the issue you have to re-iterate your data to get the latest version. See code below :
That's it. Happy Coding 🤘