Filter collection of Page Nodes by Custom Field

Posted by chunt@kentuckycenter.org on 15-Jul-2019 18:30

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;
   }
}

All Replies

Posted by jread on 16-Jul-2019 17:16

There are two examples of how to get a single page by ID at this link also included below: [View:https://www.progress.com/documentation/sitefinity-cms/for-developers-query-a-pagenode-by-id:550:50]

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;
        }
    }
}


Posted by chunt@kentuckycenter.org on 18-Jul-2019 01:43

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

This thread is closed