Can you query pages based on enabled features?

Dalton Kirk asked on September 25, 2023 17:30

I'm using the IPageRetriever to query multiple page types by using the RetrieveMultiple() method. Is is possible to exclude pages that do not have the Page Builder feature or the URL feature? Or is there something on the TreeNode object I can check once the query has returned the list of tree nodes?

Correct Answer

Jono Rickard answered on September 26, 2023 03:28

Heya Dalton,

Brenden is correct here. How that would look is slightly tricky.

Usually you can just do a join on the DataQuery with DataQuery.Source(source => source.LeftJoin("CMS_Tree.ClassName", "CMS_Class.ClassName"));

But doing joins with DocumentQuery are a bit of a pain cause regardless of what columns you set, kentico will always inlcude system columns like DocumentId, ClassName, etc & if you try to join CMS_Class like above, you'll get an ambigious column error on the ClassName column, on a column you dont even add, so you cant even fully qualify it.

Instead, I'd reccommend approaching it from the other direction - and have a preliminary query to retrieve all the relevant class names & include it as an additional where condition on the page query, so something like:

       var relevantPageTypeClassNames = DataClassInfoProvider.GetClasses()
                                   .WhereTrue(nameof(DataClassInfo.ClassIsNavigationItem))
                                   //.WhereTrue(nameof(DataClassInfo.ClassHasMetadata))
                                   //.WhereTrue(nameof(DataClassInfo.ClassUsesPageBuilder))
                                   //.WhereTrue(nameof(DataClassInfo.ClassHasURL))
                                   .AsSingleColumn(nameof(DataClassInfo.ClassName));
        pageRetriever.RetrieveMultiple(query =>
        {
            //query.Where(...) //Your existing query 
            query.WhereIn(nameof(TreeNode.ClassName), relevantPageTypeClassNames);
        });
0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on September 25, 2023 17:39

That information is regarding features enabled/disabled for a page type are on the Class definition and not the node definition. You'd have to join the cms_class table/object to your query to get that detail.

0 votesVote for this answer Mark as a Correct answer

Dalton Kirk answered on September 26, 2023 10:01

Thank you Brenden and Jono.

Jono that's a good idea thank you for the suggestion!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.