Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to get all pages of certain page type?

Vote:
 

I want to get all pages with type of ArticlePage from a controller of a partial. 

Currently I have this code and pages is null?

[ChildActionOnly]
        public ActionResult Navigation()
        {
            var model = new NavigationPartialViewModel();

            var pageTypeId = ServiceLocator.Current.GetInstance<ContentTypeRepository>()
                .Load<ArticlePage>()
                .ID
                .ToString();


            var criterias = new PropertyCriteriaCollection
            {
                new PropertyCriteria()
                {
                    Condition = CompareCondition.Equal,
                    Name = "PageTypeID",
                    Type = PropertyDataType.PageType,
                    Value = pageTypeId,
                    Required = true
                }
            };

            var repository = ServiceLocator.Current.GetInstance<IPageCriteriaQueryService>();

            var pages = repository.FindPagesWithCriteria(
                PageReference.StartPage,
                criterias);

            return PartialView(model);
        }
#265608
Oct 25, 2021 11:36
Vote:
 

Try using FindAllPagesWithCriteria instead of FindPagesWithCriteria

FYI - FindPagesWithCriteria returns all matching pages that the current user has read access for, whereas FindAllPagesWithCriteria returns all pages regardless of permissions.

#265609
Oct 25, 2021 12:29
Vote:
 

Something like this?

var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();
var contentType = contentTypeRepository.Load<ArticlePage>();
var allArticlePages = contentModelUsage.ListContentOfContentType(contentType);
#265619
Oct 25, 2021 16:51
* 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.