Filter collection of Page Nodes by Custom Field - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Filter collection of Page Nodes by Custom Field

  • Environment - currently using Sitefinity 11.0 since Sitefinity VSIX isn't up to date yet

    I am building a custom Sitefinity MVC widget. Surely the following can be done without a foreach loop but I can't seem to get the syntax correct. There will only be one matching page with the current productionSeasonId so firstordefault should work fine.

    //Collection of all page Nodes
    var pageNodes = App.WorkWith().Pages()..LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Where(p => p.NodeType == NodeType.Standard && p.GetPageData().Status == ContentLifecycleStatus.Live).ThatArePublished().Get();
    //Get page node where custom field "ProductionSeasonId" isn't null or empty and matches the current productionSeasonId
    foreach (var node in pageNodes)
        if (node.GetValue("ProductionSeasonId") != null && !node.GetValue("ProductionSeasonId").ToString().IsNullOrEmpty() && node.GetValue("ProductionSeasonId").ToString() == productionSeasonId)
          showURL = node.GetUrl().Remove(0, 2);
          showInNavigation = node.ShowInNavigation;
  • There are two examples of how to get a single page by ID at this link also included below:

    Native Api

    using System; using System.Linq; using Telerik.Sitefinity.Modules.Pages; using Telerik.Sitefinity.Pages.Model; namespace SitefinityWebApp { public class QueryPages_FindPageNodeById_NativeAPI { public PageNode FindPageNodeByIdNativeAPI(Guid pageNodeId) { PageManager pageManager = PageManager.GetManager(); PageNode node = pageManager.GetPageNodes().Where(n => n.Id == pageNodeId).FirstOrDefault(); return node; } } }

    Fluent Api

    using System.Linq;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Pages.Model;
    namespace SitefinityWebApp
        public class QueryPages_FindPagebyUrl_FluentAPI
            public PageData FindPagebyUrlFluentAPI(string urlName)
                PageData pageData = null;
                var count = 0;
                App.WorkWith().Pages().Where(pN => pN.UrlName == urlName).Count(out count);
                if (count != 0)
                    pageData = App.WorkWith().Pages().Where(pN => pN.UrlName == urlName).Get().First().Page;
                return pageData;

  • That is how to get a page by the built in ID, not by a custom Field in the page properties.