Try our conversational search powered by Generative AI!

GetChildren fails to retrieve new page type


We have a developer who added a new page type to our EpiServer application.  Upon adding pages of the new type via the CMS admin interface, we are able to see the new pages in the EpiServer Admin Navigation Pane.

However, code that we have written to display navigable pages in a Site Map or a navigation menu fails to render these new pages.  Why do they successfully appear in the CMS Admin interface, but fail to render otherwise?

Our site is originally based off Alloy.  Here is the new page type our developer created.

using EPiServer;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Shell.ObjectEditing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace OurSite.Models.Pages
    [ContentType(DisplayName = "External Link", GUID = "71e50285-235c-4f8c-828d-9e20d4a8216f", Description = "A page that links directly to a pdf or an external site.")]
    public class ExternalLinkPage : BasePage
            Name = "External Link",
            Description = "Set the Link URL",
            GroupName = SystemTabNames.Content,
            Order = 10)]
        public virtual Url Link { get; set; }

        [SelectOne(SelectionFactoryType = typeof(TargetSelectionFactory))]
            Name = "Target",
            Description = "Set the link target",
            GroupName = SystemTabNames.Content,
            Order = 20)]
        public virtual String Target { get; set; }

    public class TargetSelectionFactory : ISelectionFactory
        public IEnumerable GetSelections(ExtendedMetadata metadata)
            return new ISelectItem[] { 
                new SelectItem() { Text = "Open in New window", Value = "_blank" }, 
                new SelectItem() { Text = "Open in Same Window", Value = "_self" } 

And here is an example of the Razor code.  When the SubNav collection gets filled, we expect that the new pages will be retrieved by GetChildren().  But they never appear.  I've added some comments below showing where this fails.

    var mainNavRef = DataFactory.Instance.GetChildren(ContentReference.StartPage);
    bool showSecondLevelNavigation = true;
    bool showThirdLevelNavigation = true;


@{ IEnumerable SubNav = new PageDataCollection(); IEnumerable ThirdNav = new PageDataCollection(); foreach (PageData topLevelPage in mainNavRef) { var topPageRef = DataFactory.Instance.Get(topLevelPage.ContentLink.ToPageReference()); if (topLevelPage.HasTemplate() && topLevelPage.IsVisibleOnSite() && topPageRef.HideSitemap == false) { // We have pages of the new type at this level, and expect to see them appear here. // But when the foreach runs, the new pages are not in the collection. SubNav = DataFactory.Instance.GetChildren(topLevelPage.ContentLink); bool weHaveSubPages = false; foreach (PageData subPage in SubNav) {

Since the pages appear in the Episerver CMS admin interface successfully, I suspect the problem rests with how we are executing GetChildren, or that we need to take a different approach.  Thanks for your help.

Edited, Feb 02, 2017 21:11

Have you created a view for the new page type? .HasTemplate() will remove pages that has no template/view.

Feb 02, 2017 23:00

Thanks Johan.  Yes, there is a template for this view.

Troubleshooting this a bit more, we have some alternate code that builds the navigation tree in a separate class, which is actually finding the new page type children.  It's a lot cleaner than the original implementation posted above, so I'm going to run with that.  Thanks for helping me out.

Feb 02, 2017 23:16
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.