We have a developer who added a new page type to our EpiServer 8.0.0.0 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.")] [ImageUrl("~/Static/img/previews/external-link.png")] public class ExternalLinkPage : BasePage { [CultureSpecific] [Display( Name = "External Link", Description = "Set the Link URL", GroupName = SystemTabNames.Content, Order = 10)] public virtual Url Link { get; set; } [CultureSpecific] [SelectOne(SelectionFactoryType = typeof(TargetSelectionFactory))] [Display( 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<PageData>(ContentReference.StartPage); bool showSecondLevelNavigation = true; bool showThirdLevelNavigation = true; }<div class="site-map"><h3><a href="/">Home</a></h3> @{ IEnumerable<IContent> SubNav = new PageDataCollection(); IEnumerable<IContent> ThirdNav = new PageDataCollection(); foreach (PageData topLevelPage in mainNavRef) { var topPageRef = DataFactory.Instance.Get<BasePage>(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<PageData>(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.